Skip to content

Commit

Permalink
update to git submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-taxiera committed Jan 16, 2024
1 parent f1ffb78 commit 1897634
Show file tree
Hide file tree
Showing 10 changed files with 568 additions and 116 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "extern/CommonLibSF"]
path = extern/CommonLibSF
url = https://github.com/Starfield-Reverse-Engineering/CommonLibSF
52 changes: 33 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG OFF)
set(CMAKE_OPTIMIZE_DEPENDENCIES ON)

message("CMAKE_SHARED_LINKER_FLAGS: ${CMAKE_SHARED_LINKER_FLAGS}")

Expand All @@ -27,41 +28,54 @@ configure_file(
set(PUBLIC_HEADER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}")

set(
headers
include/Utility.h
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/Discord.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Hooks.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/PresenceManager.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Settings.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Translations.cpp
)

set(
sources
src/Discord.cpp
src/Hooks.cpp
src/Main.cpp
src/PresenceManager.cpp
src/Settings.cpp
src/Translations.cpp

${CMAKE_CURRENT_BINARY_DIR}/version.rc
source_group(
TREE ${CMAKE_CURRENT_SOURCE_DIR}
FILES
${SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/include/Utility.h
${CMAKE_CURRENT_SOURCE_DIR}/include/Plugin.h
)

source_group(
TREE ${CMAKE_CURRENT_SOURCE_DIR}
FILES ${headers} ${sources}
TREE ${CMAKE_CURRENT_BINARY_DIR}
FILES ${CMAKE_CURRENT_BINARY_DIR}/version.rc

)

########################################################################################################################
## Configure target DLL
########################################################################################################################
find_package(CommonLibSF CONFIG REQUIRED)
add_commonlibsf_plugin(
#find_package(CommonLibSF CONFIG REQUIRED)
#add_commonlibsf_plugin(
# ${PROJECT_NAME}
# AUTHOR "Alex Taxiera"
# SOURCES ${headers} ${sources}
#)
add_library(
${PROJECT_NAME}
AUTHOR "Alex Taxiera"
SOURCES ${headers} ${sources}
SHARED
${SOURCES}
${CMAKE_CURRENT_SOURCE_DIR}/include/Plugin.h
${CMAKE_CURRENT_BINARY_DIR}/version.rc
.clang-format
vcpkg.json
)

add_subdirectory(extern/CommonLibSF)
target_link_libraries(${PROJECT_NAME} PRIVATE CommonLibSF::CommonLibSF)

find_library(DISCORD_RPC discord-rpc)
target_link_libraries(${PROJECT_NAME} PRIVATE ${DISCORD_RPC})

add_library("${PROJECT_NAME}::${PROJECT_NAME}" ALIAS "${PROJECT_NAME}")

find_path(PLF_NANOTIMER_INCLUDE_DIRS "plf_nanotimer.h")
find_path(SIMPLEINI_INCLUDE_DIRS "SimpleIni.h")
Expand Down
1 change: 1 addition & 0 deletions extern/CommonLibSF
Submodule CommonLibSF added at e52044
36 changes: 32 additions & 4 deletions include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,38 @@ namespace Resources
{
constexpr const char* StarfieldLogo = "constellation";
const std::map<std::uint32_t, CompanionData> companionDataMap = {
{ 0x000059A9, { .smallImageKey = "andreja_small" } },
{ 0x00005986, { .smallImageKey = "sarah_morgan_small" } },
{ 0x00005788, { .smallImageKey = "barrett_small" } },
{ 0x0029D488, { .smallImageKey = "sam_coe_small" } },
{ 0x00005788, { .smallImageKey = "barrett_small" } }, // Barrett
{ 0x00005986, { .smallImageKey = "sarah_morgan_small" } }, // Sarah Morgan
{ 0x000059A9, { .smallImageKey = "andreja_small" } }, // Andreja
{ 0x001631C5, { .smallImageKey = "sam_coe_small" } }, // Adoring Fan
{ 0x0029D488, { .smallImageKey = "sam_coe_small" } }, // Sam Coe
// elite crew
{ 0x00299F66, { .smallImageKey = "andreja_small" } }, // Amelia Earhart
{ 0x0016B3D0, { .smallImageKey = "andreja_small" } }, // Andromeda Kepler
{ 0x001F0262, { .smallImageKey = "andreja_small" } }, // Autumn MacMillan
{ 0x0020DC69, { .smallImageKey = "andreja_small" } }, // Betty Howser
{ 0x001CDAFC, { .smallImageKey = "andreja_small" } }, // Dani Garcia
{ 0x0022198C, { .smallImageKey = "andreja_small" } }, // Erick Von Price
{ 0x0017A859, { .smallImageKey = "andreja_small" } }, // Ezekiel
{ 0x00015064, { .smallImageKey = "andreja_small" } }, // Gideon Aker
{ 0x002B17C4, { .smallImageKey = "andreja_small" } }, // Hadrian
{ 0x0000563C, { .smallImageKey = "andreja_small" } }, // Heller
{ 0x001D898E,
{ .smallImageKey = "andreja_small" } }, // Jessamine Griffin
{ 0x00005639, { .smallImageKey = "andreja_small" } }, // Supervisor Lin
{ 0x0017A858, { .smallImageKey = "andreja_small" } }, // Lyle Brewer
{ 0x00015062, { .smallImageKey = "andreja_small" } }, // Marika Boros
{ 0x0016D16A, { .smallImageKey = "andreja_small" } }, // Mickey Caviar
{ 0x0029C982, { .smallImageKey = "andreja_small" } }, // Moara Otero
{ 0x001593F8, { .smallImageKey = "andreja_small" } }, // Omari Hassan
{ 0x001A9054, { .smallImageKey = "andreja_small" } }, // You?
{ 0x000C4632, { .smallImageKey = "andreja_small" } }, // Rafael Aguerro
{ 0x001A0CB1,
{ .smallImageKey = "andreja_small" } }, // Dr. Rosie Tannehill
{ 0x00015063,
{ .smallImageKey = "andreja_small" } }, // Simeon Bankowski
{ 0x00147954, { .smallImageKey = "andreja_small" } }, // Sophia Grace
{ 0x000057BE, { .smallImageKey = "andreja_small" } }, // Vasco
};
};

Expand Down
4 changes: 3 additions & 1 deletion include/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

namespace Hooks
{
void Install() noexcept;
void InstallMenuHook() noexcept;

void InstallMainHook() noexcept;
}
48 changes: 48 additions & 0 deletions include/Plugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

namespace Plugin
{
using namespace std::string_view_literals;

static constexpr auto Name{ "StarfieldRichPresence"sv };
static constexpr auto Author{ "Alex Taxiera"sv };
static constexpr auto Version{
REL::Version{0, 0, 1, 0}
};
}

namespace SFSE
{
constexpr REL::Version RUNTIME_SF_1_8_88(1, 8, 88, 0);
}

extern "C"
{
__declspec(dllexport) SFSE::PluginVersionData SFSEPlugin_Version = {
SFSE::PluginVersionData::kVersion,

1, // version 1
"Starfield Rich Presence",
"Alex Taxiera",

1, // yes address independent
0, // not structure independent
{ SFSE::RUNTIME_SF_1_8_88.pack(), 0 },

0, // works with any version of the script extender. you probably do not need to put anything here
0, 0, // set these reserved fields to 0
};
};

//SFSEPluginVersion = []() noexcept {
// SFSE::PluginVersionData data{};
//
// data.PluginVersion(Plugin::Version);
// data.PluginName(Plugin::Name);
// data.AuthorName(Plugin::Author);
// data.UsesAddressLibrary(true);
// data.IsLayoutDependent(true);
// data.CompatibleVersions({ SFSE::RUNTIME_LATEST });
//
// return data;
//}();
32 changes: 19 additions & 13 deletions src/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace Hooks
{
plf::nanotimer timer;

uintptr_t addresses[2] = {
REL::Relocation(REL::ID(148991), 0xCD).address(), // menu thread
REL::Relocation(REL::ID(146554), 0x10)
.address() // main game thread
};
auto menuThreadAddress =
REL::Relocation(REL::ID(148991), 0xCD).address();

auto mainThreadAddress =
REL::Relocation(REL::ID(146554), 0x10).address();

bool ShouldTriggerChange()
{
Expand Down Expand Up @@ -43,17 +43,23 @@ namespace Hooks
};
} // namespace Presence

void Install() noexcept
void InstallMenuHook() noexcept
{
logger::info("Installing hooks");
Presence::timer.start();

// setup hooks
for (const auto& address : Presence::addresses) {
logger::debug("Installing Presence hook at {:x}", address);
SFSE::stl::write_thunk_call<Presence::Hook>(address);
}
logger::debug("Installing Presence hook at {:x}",
Presence::menuThreadAddress);
SFSE::stl::write_thunk_call<Presence::Hook>(
Presence::menuThreadAddress);
}

void InstallMainHook() noexcept
{
Presence::timer.start();

logger::info("Installed hooks");
logger::debug("Installing Presence hook at {:x}",
Presence::mainThreadAddress);
SFSE::stl::write_thunk_call<Presence::Hook>(
Presence::mainThreadAddress);
}
} // namespace Hooks
30 changes: 20 additions & 10 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@
#include "Hooks.h"
#include "Settings.h"
#include "Translations.h"
#include "PresenceManager.h"

// SFSE message listener, use this to do stuff at specific moments during runtime
void Listener(SFSE::MessagingInterface::Message* message) noexcept
{
if (message->type <=> SFSE::MessagingInterface::kPostPostLoad == 0) {
Settings::LoadSettings();
Translations::LoadTranslations();
auto ready = Discord::InitializePresence();
if (!ready) {
logger::error("Failed to initialize Discord Rich Presence");
return;
switch (message->type) {
case SFSE::MessagingInterface::kPostPostLoad:
{
Settings::LoadSettings();
Translations::LoadTranslations();

auto ready = Discord::InitializePresence();
if (!ready) {
logger::error("Failed to initialize Discord Rich Presence");
return;
}

Hooks::InstallMenuHook();
break;
}
case SFSE::MessagingInterface::kPostPostDataLoad:
{
Hooks::InstallMainHook();
break;
}
Hooks::Install();
}
}

// Main SFSE plugin entry point, initialize everything here
SFSEPluginLoad(const SFSE::LoadInterface* sfse)
{
Init(sfse);
Expand Down
Loading

0 comments on commit 1897634

Please sign in to comment.