Skip to content

Commit

Permalink
changes for pr6
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskarth committed Jul 15, 2019
1 parent 0827142 commit 9feb98b
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 56 deletions.
8 changes: 4 additions & 4 deletions BaseMod/ExampleMod.cpp
Expand Up @@ -26,7 +26,7 @@ using namespace SML::Mod;
using namespace SML::Objects;

// Version of SML that this mod was compiled for.
#define SML_VERSION "1.0.0-pr5"
#define SML_VERSION "1.0.0-pr6"

// define the mod name for easy changing and simple use
#define MOD_NAME "ExampleMod"
Expand All @@ -40,10 +40,10 @@ using namespace SML::Objects;
#define INFO(msg) LOG(msg)

//log a warning message to the console
#define WARNING(msg)
#define WARN(msg) SML::Utility::warningMod(MOD_NAME, msg)

//log an error message to the console
#define ERROR(msg) SML::Utility::errorMod(MOD_NAME, msg);
#define ERR(msg) SML::Utility::errorMod(MOD_NAME, msg)

// Config
json config = SML::Utility::JsonConfig::load(MOD_NAME, {
Expand Down Expand Up @@ -77,7 +77,7 @@ Mod::Info modInfo {
MOD_NAME,

// Version
"0.2",
"1.0.0",

// Description
"A basic mod created to showcase SML's functionality.",
Expand Down
4 changes: 2 additions & 2 deletions SatisfactoryModLoader/SatisfactoryModLoader.h
Expand Up @@ -7,8 +7,8 @@
#include <mod/ModHandler.h>

namespace SML {
static const std::string modLoaderVersion = "1.0.0-pr5"; // SML's version
static const std::string targetVersion[] = { "102023", "101829" }; //CLs of Satisfactory, 1st is normal CL and 2nd is experimental CL
static const std::string modLoaderVersion = "1.0.0-pr6"; // SML's version
static const int targetVersion = 102023; //CLs of Satisfactory, 1st is normal CL and 2nd is experimental CL
static bool loadConsole = true;
static bool debugOutput = false;
static bool supressErrors = false;
Expand Down
29 changes: 18 additions & 11 deletions SatisfactoryModLoader/assets/AssetFunctions.cpp
Expand Up @@ -9,6 +9,7 @@
#include <Lib.h>
#include "FObjectSpawnParameters.h"
#include <SatisfactoryModLoader.h>
#include <mod/MathFunctions.h>
#include <util/Utility.h>
#include <util/FString.h>

Expand All @@ -20,10 +21,14 @@ namespace SML {
}
namespace Mod {
namespace Functions {
SML_API SDK::UObject* loadObjectFromPak(SDK::UClass *ObjectClass, const wchar_t *InName) {
SML_API SDK::UObject* loadObjectFromPak(SDK::UClass* ObjectClass, const wchar_t *InName) {
return Assets::AssetLoader::loadObjectSimple(ObjectClass, InName);
}

SML_API SDK::UObject* loadObjectFromPak(const wchar_t *InName) {
return Assets::AssetLoader::loadObjectSimple(SDK::UClass::StaticClass(), InName);
}

SML_API SDK::UClass* spawnActor(void* UWorld, void* *UClass, void* *FVector, void* *FRotator, void* *FActorSpawnParameters) {
PVOID spawnActorFn = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "UWorld::SpawnActor");
auto spawnActorFunc = (SDK::UClass* (WINAPI*)(void*, void*, void*, void*, void*))spawnActorFn;
Expand Down Expand Up @@ -61,27 +66,29 @@ namespace SML {

SML_API SDK::UClass* spawnActor(SDK::UObject* obj, float x, float y, float z, float pitch, float roll, float yaw) {
FActorSpawnParameters params = FActorSpawnParameters();
SDK::FVector vec = SDK::FVector();
vec.X = x;
vec.Y = y;
vec.Z = z;
SDK::FRotator rot = SDK::FRotator();
rot.Pitch = pitch;
rot.Roll = roll;
rot.Yaw = yaw;
SDK::FVector vec = Functions::makeVector(x, y, z);
SDK::FRotator rot = Functions::makeRotator(pitch, roll, yaw);
PVOID spawnActorFn = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "UWorld::SpawnActor");
auto spawnActor = (SDK::UClass* (WINAPI*)(void*, void*, void*, void*, void*))spawnActorFn;
return spawnActor(getWorld(), obj, &vec, &rot, &params);
}

SML_API void addRecipe(const wchar_t* recipeName) {
SDK::UClass* recipe = static_cast<SDK::UClass*>(loadObjectFromPak(recipeName));
PVOID addAvailableRecipeFn = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "AFGRecipeManager::AddAvailableRecipe");
auto addAvailableRecipe = static_cast<SDK::AFGRecipeManager* (WINAPI*)(void*, void*)>(addAvailableRecipeFn);
SDK::TSubclassOf<SDK::UFGRecipe> recipeClass(recipe);
addAvailableRecipe(static_cast<SDK::AFGGameState*>(getWorld()->GameState)->mRecipeManager, recipe);
}

SML_API void addRecipe(SDK::UClass* recipe) {
PVOID addAvailableRecipeFn = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "AFGRecipeManager::AddAvailableRecipe");
auto addAvailableRecipe = static_cast<SDK::AFGRecipeManager* (WINAPI*)(void*, void*)>(addAvailableRecipeFn);
SDK::TSubclassOf<SDK::UFGRecipe> recipeClass(recipe);
addAvailableRecipe(static_cast<SDK::AFGGameState*>(reinterpret_cast<SDK::UWorld*>(getWorld())->GameState)->mRecipeManager, recipe);
addAvailableRecipe(static_cast<SDK::AFGGameState*>(getWorld()->GameState)->mRecipeManager, recipe);
}

SML_API SDK::FInventoryStack makeItemStack(SDK::UClass* clazz, const int& amount) {
SML_API SDK::FInventoryStack makeItemStack(SDK::UClass* clazz, int amount) {
SDK::FInventoryStack stack = SDK::FInventoryStack();
SDK::FInventoryItem item = SDK::FInventoryItem();

Expand Down
20 changes: 18 additions & 2 deletions SatisfactoryModLoader/assets/AssetFunctions.h
Expand Up @@ -32,7 +32,17 @@ namespace SML {
* The asset name must be of the following format: \\Game\\FactoryGame\\Path\\To\\Asset\\AssetFile.AssetFile
* If you are loading a blueprint, the name must have a _C appended to the end.
*/
SML_API SDK::UObject* loadObjectFromPak(SDK::UClass *ObjectClass, const wchar_t *InName);
SML_API SDK::UObject* loadObjectFromPak(SDK::UClass *ObjectClass, const wchar_t* InName);

/**
* This function has been largely replaced by the asset caching system. To prevent slowdowns, use that instead!
*
* Load an object from a pak file. Will crash if the pak is not installed.
*
* The asset name must be of the following format: \\Game\\FactoryGame\\Path\\To\\Asset\\AssetFile.AssetFile
* If you are loading a blueprint, the name must have a _C appended to the end.
*/
SML_API SDK::UObject* loadObjectFromPak(const wchar_t* InName);

/**
* Spawns an actor at a given location, when given the world.
Expand Down Expand Up @@ -69,6 +79,12 @@ namespace SML {
*/
SML_API SDK::UClass* spawnActor(SDK::UObject* obj, float x, float y, float z, float pitch, float roll, float yaw);

/**
* Wrapper for addRecipe(SDK::UClass*) to do everything for you.
* Call this in beginPlay().
*/
SML_API void addRecipe(const wchar_t* recipeName);

/**
* Adds a UFGRecipe to the game.
* Code kindly provided by Trxnce.
Expand All @@ -79,7 +95,7 @@ namespace SML {
* Returns an ItemStack from an item class and an item amount.
* Code kindly provided by Trxnce.
*/
SML_API SDK::FInventoryStack makeItemStack(SDK::UClass* clazz, const int& amount);
SML_API SDK::FInventoryStack makeItemStack(SDK::UClass* clazz, int amount);

/**
* Adds an item with an amount to the player's inventory.
Expand Down
2 changes: 2 additions & 0 deletions SatisfactoryModLoader/game/Global.cpp
Expand Up @@ -6,4 +6,6 @@ namespace SML {
void SML::Objects::AFGPlayerController::EnterChatMessage(FString* inMessage) {}

void SML::Objects::FEngineLoop::Init() {}

void SML::Objects::FPakPrecacher::DoSignatureCheck(bool b, IAsyncReadRequest* a, int i) {}
}
12 changes: 12 additions & 0 deletions SatisfactoryModLoader/game/Global.h
Expand Up @@ -8,6 +8,11 @@

namespace SML {
namespace Objects {

class IAsyncReadRequest {

};

class UWorld {
public:
void Tick(enum ELevelTick TickType, float DeltaSeconds);
Expand Down Expand Up @@ -63,6 +68,13 @@ namespace SML {
};

DEFINE_METHOD(FPakPlatformFile::GetPakSigningKeys);

class FPakPrecacher {
public:
void DoSignatureCheck(bool b, IAsyncReadRequest* a, int i);
};

DEFINE_METHOD(FPakPrecacher::DoSignatureCheck);
}
}

Expand Down
34 changes: 10 additions & 24 deletions SatisfactoryModLoader/mod/Hooks.cpp
Expand Up @@ -29,6 +29,10 @@ namespace SML {
::subscribe<&Objects::FEngineLoop::Init>([this](Functions::ModReturns* ret, Objects::FEngineLoop* engineLoop) {
Hooks::engineInit(ret, engineLoop);
});

::subscribe<&Objects::FPakPrecacher::DoSignatureCheck>([this](Functions::ModReturns* ret, Objects::FPakPrecacher* pak, bool b, Objects::IAsyncReadRequest* request, int i) {
ret->useOriginalFunction = false;
});
}
};

Expand All @@ -44,46 +48,25 @@ namespace SML {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());

// find the function by name
//chatFunc = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "AFGPlayerController::EnterChatMessage");
//DetourAttach(&(PVOID&)chatFunc, playerSentMessage);

//::subscribe<&Objects::AFGPlayerController::EnterChatMessage>(playerSentMessage);

LambdaFunctionHooks().hookLambdas();

playerAddedFunc = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "AFGGameState::NotifyPlayerAdded");
DetourAttach(&(PVOID&)playerAddedFunc, playerAdded);

//engineInitFunc = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "FEngineLoop::Init");
//DetourAttach(&(PVOID&)engineInitFunc, engineInit);

playerControllerAddedFunc = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "AFGPlayerController::PostLoad");
DetourAttach(&(PVOID&)playerControllerAddedFunc, playerControllerAdded);

levelDestroyFunc = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "ULevel::~ULevel");
DetourAttach(&(PVOID&)levelDestroyFunc, levelDestructor);

sigCheckFunc = DetourFindFunction("FactoryGame-Win64-Shipping.exe", "FPakPrecacher::DoSignatureCheck");
DetourAttach(&(PVOID&)sigCheckFunc, sigCheck);

Utility::info("Installed hooks!");

DetourTransactionCommit();
}

void Hooks::sigCheck(void* self, bool b, void* v) {

}

/*
void Hooks::playerControllerAdded(SDK::AFGPlayerController* controller) {
if (Assets::SinglePlayerController == nullptr) {
Assets::SinglePlayerController = controller;
}
auto pointer = (void(WINAPI*)(void*))playerControllerAddedFunc;
pointer(controller);
}
}*/

void Hooks::levelDestructor(SDK::ULevel* level) {

Expand All @@ -96,17 +79,19 @@ namespace SML {
void Hooks::engineInit(Functions::ModReturns* ret, Objects::FEngineLoop* engine) {
//caching of assets
modHandler.currentStage = GameStage::RUN;
for (std::pair< const wchar_t*, SDK::UObject*> asset : modHandler.assetCache) {
for (std::pair<const wchar_t*, SDK::UObject*> asset : modHandler.assetCache) {
modHandler.assetCache[asset.first] = Assets::AssetLoader::loadObjectSimple(SDK::UClass::StaticClass(), asset.first);
}

//load delayed coremods
for (const wchar_t* dll : delayedCoremods) {
LoadLibraryW(dll);
}

ret->useOriginalFunction = true;
}

/*
void Hooks::playerAdded(SDK::AFGGameState* gameState, SDK::AFGCharacterPlayer* player) {
auto pointer = (void(WINAPI*)(void*, void*))playerAddedFunc;
//Utility::info("Player Added: ", player->GetName(), " - Controlled: ", player->IsControlled(), " - IsLocallyControlled: ", player->IsLocallyControlled());
Expand All @@ -115,6 +100,7 @@ namespace SML {
}
pointer(gameState, player);
}
*/

// parse commands when the player sends a message
void Hooks::playerSentMessage(Functions::ModReturns* ret, Objects::AFGPlayerController* player, Objects::FString* messageIn) {
Expand Down
9 changes: 3 additions & 6 deletions SatisfactoryModLoader/mod/Hooks.h
Expand Up @@ -22,16 +22,13 @@ namespace SML {

static void hookFunctions();


static void engineInit(Functions::ModReturns* ret, Objects::FEngineLoop* fEngine);

static void getWorld(void* self);

static void sigCheck(void* self, bool b, void* v);
//static void getWorld(void* self);

static void playerAdded(SDK::AFGGameState* gameState, SDK::AFGCharacterPlayer* player);
//static void playerAdded(SDK::AFGGameState* gameState, SDK::AFGCharacterPlayer* player);

static void playerControllerAdded(SDK::AFGPlayerController* self);
//static void playerControllerAdded(SDK::AFGPlayerController* self);

static void levelDestructor(SDK::ULevel* level);

Expand Down
13 changes: 7 additions & 6 deletions SatisfactoryModLoader/util/Utility.cpp
Expand Up @@ -47,20 +47,21 @@ namespace SML {
}

//target[0] = normal CL, target [1] = experimental CL
void checkVersion(const std::string target[2]) {
void checkVersion(const int target) {
std::wstring satisVersion{ call<&Objects::BuildSettings::GetBuildVersion>() };
std::string str(satisVersion.begin(), satisVersion.end());
info(str);
if (str.substr(str.length() - 6, str.length()) == target[0]) {
int version = std::atoi(str.substr(str.length() - 6, str.length()).c_str());
if (version == target) {
info("Version check passed!");
}
else if (str.substr(str.length() - 6, str.length()) == target[1]) {
warning("SML is running on the experimental branch, issues may occur!");
else if (version > target) {
warning("SML is out of date with the latest Satisfactory! Report any issues on the discord!");
}
else {
else if (version < target){
error("WARNING: Version check failed");
if (!supressErrors) {
int ret = MessageBoxA(NULL, "The version of SML that you are using is not compatible with your version of Satisfactory!\nIf SML is not available for the latest version of satisfactory, please yell at SuperCoder to compile one.\nPress Ok to continue at your own discresion or cancel to stop the program.", "SatisfactoryModLoader Warning", MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONEXCLAMATION);
int ret = MessageBoxA(NULL, "The version of Satisfactory that you are running is too old for the current version of SML! Please update Satisfactory otherwise SML may run into errors. \nPress Ok to continue at your own discresion or cancel to stop the program.", "SatisfactoryModLoader Warning", MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONEXCLAMATION);
if (ret == IDCANCEL) {
exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion SatisfactoryModLoader/util/Utility.h
Expand Up @@ -41,7 +41,7 @@ namespace SML {

void SML_API setConsoleColor(ConsoleColor color);

void SML_API checkVersion(const std::string target[2]);
void SML_API checkVersion(const int target);

void SML_API log();

Expand Down

0 comments on commit 9feb98b

Please sign in to comment.