SteamLink.Build.cs
using UnrealBuildTool;
using System.IO;
public class SteamLink : ModuleRules
{
public SteamLink(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
PublicIncludePaths.AddRange(new string[] { Path.Combine(ModuleDirectory, "Steamworks", "Include") });
PrivateIncludePaths.AddRange(new string[] {});
PublicDependencyModuleNames.AddRange(new string[] { "Core" });
PrivateDependencyModuleNames.AddRange(new string[] { "CoreUObject","Engine","Slate","SlateCore", "Projects" });
DynamicallyLoadedModuleNames.AddRange(new string[] {});
if (Target.Platform == UnrealTargetPlatform.Win64)
{
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "Steamworks", "steam_api64.lib"));
PublicDelayLoadDLLs.Add("steam_api64.dll");
RuntimeDependencies.Add(
Path.Combine("$(BinaryOutputDir)", "steam_api64.dll"),
Path.Combine(ModuleDirectory, "Steamworks", "steam_api64.dll")
);
}
}
}
SteamLink.cpp
#include "SteamLink.h"
#include "Interfaces/IPluginManager.h"
#include "steam_api.h"
#define LOCTEXT_NAMESPACE "FSteamLinkModule"
void FSteamLinkModule::StartupModule()
{
FString BaseDir = IPluginManager::Get().FindPlugin("SteamLink")->GetBaseDir();
FString DLLPath = FPaths::Combine(*BaseDir, TEXT("Binaries/Win64/steam_api64.dll"));
DLLHandle = !DLLPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*DLLPath) : nullptr;
if (DLLHandle)
{
UE_LOG(LogTemp, Log, TEXT("Steam DLL loaded successfully."));
if (SteamAPI_Init())
{
UE_LOG(LogTemp, Log, TEXT("Steam API initialized successfully."));
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to initialize Steam API."));
}
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to load Steam DLL."));
}
}
void FSteamLinkModule::ShutdownModule()
{
FPlatformProcess::FreeDllHandle(DLLHandle);
DLLHandle = nullptr;
SteamAPI_Shutdown();
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FSteamLinkModule, SteamLink)
SteamLink.h
#pragma once
#include "Modules/ModuleManager.h"
class FSteamLinkModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
private:
void* DLLHandle;
};