Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions FicsitRemoteMonitoring.uplugin
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.5.2",
"SemVersion": "1.5.2",
"VersionName": "1.5.3",
"SemVersion": "1.5.3",
"AcceptsAnyRemoteVersion": true,
"FriendlyName": "Ficsit Remote Monitoring",
"Description": "Statistical and GeoLocation Monitoring for Satisfactory",
Expand Down Expand Up @@ -42,4 +42,4 @@
"GameVersion": ">=491125",
"RequiredOnRemote": false,
"BuiltInInitialFeatureState": "Active"
}
}
130 changes: 130 additions & 0 deletions Source/FicsitRemoteMonitoring/Private/Endpoints/World/Environment.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#include "Endpoints/World/Environment.h"

#include "FGCreatureSubsystem.h"
#include "FGGasPillar.h"
#include "FGSporeFlower.h"
#include "FicsitRemoteMonitoring.h"
#include "RemoteMonitoringLibrary.h"
#include "Creature/FGCreatureSpawner.h"
#include "Kismet/GameplayStatics.h"

void UEnvironment::getHazards(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray) {

UClass* GasPillarClass = AFGGasPillar::StaticClass();
TArray<AActor*> FoundActors;

UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), GasPillarClass, FoundActors);
for (AActor* GasPillarActor : FoundActors) {

AFGGasPillar* GasPillar = Cast<AFGGasPillar>(GasPillarActor);

TSharedPtr<FJsonObject> JGasPillar = CreateBaseJsonObject(GasPillar);

JGasPillar->Values.Add("ClassName", MakeShared<FJsonValueString>(UKismetSystemLibrary::GetClassDisplayName(GasPillar->GetClass())));
JGasPillar->Values.Add("location", MakeShared<FJsonValueObject>(getActorJSON(GasPillar)));
JGasPillar->Values.Add("features", MakeShared<FJsonValueObject>(getActorFeaturesJSON(GasPillar, TEXT("Gas Pillar"), TEXT("Gas Pillar"))));

OutJsonArray.Add(MakeShared<FJsonValueObject>(JGasPillar));
};
};

void UEnvironment::getSpawners(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray) {

UClass* CreatureSpawnerClass = AFGCreatureSpawner::StaticClass();
TArray<AActor*> FoundActors;

UFGGameUserSettings* UserSettings = UFGGameUserSettings::GetFGGameUserSettings();
if (!UserSettings)
{
UE_LOG(LogFRMConfigManager, Error, TEXT("GetConfig: UserSettings is null"));
return;
}

const bool bDisableArachnid = UserSettings->GetBoolOptionValue(TEXT("FG.GameRules.DisableArachnidCreatures"));

UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), CreatureSpawnerClass, FoundActors);
for (AActor* CreatureSpawnerActor : FoundActors) {

AFGCreatureSpawner* CreatureSpawner = Cast<AFGCreatureSpawner>(CreatureSpawnerActor);

TSharedPtr<FJsonObject> JCreatureSpawner = CreateBaseJsonObject(CreatureSpawner);

AFGCreature* SpawnableCreature;

if (bDisableArachnid)
{
SpawnableCreature = CreatureSpawner->GetCreatureClassArachnidOverride()->GetDefaultObject<AFGCreature>();
} else
{
SpawnableCreature = CreatureSpawner->GetCreatureClass()->GetDefaultObject<AFGCreature>();
};

TSharedPtr<FJsonObject> JSpawnableCreature= MakeShared<FJsonObject>();

if (IsValid(SpawnableCreature))
{
FString ClassName = UKismetSystemLibrary::GetClassDisplayName(SpawnableCreature->GetClass());

TSharedPtr<FJsonObject> JRoaming = MakeShared<FJsonObject>();
JRoaming->SetNumberField("MinRoaming", SpawnableCreature->GetRoamingDistance().Min);
JRoaming->SetNumberField("MaxRoaming", SpawnableCreature->GetRoamingDistance().Max);

JSpawnableCreature->SetStringField("ClassName", ClassName);
JSpawnableCreature->SetObjectField("Roaming", JRoaming);
JSpawnableCreature->SetNumberField("SpawnDistance", SpawnableCreature->GetSpawnDistance());
JSpawnableCreature->SetStringField("State", StaticEnum<ECreatureState>()->GetNameStringByValue((int64)SpawnableCreature->GetCurrentBehaviorState()));
}

JCreatureSpawner->Values.Add("ClassName", MakeShared<FJsonValueString>(UKismetSystemLibrary::GetClassDisplayName(CreatureSpawner->GetClass())));
JCreatureSpawner->Values.Add("location", MakeShared<FJsonValueObject>(getActorJSON(CreatureSpawner)));
JCreatureSpawner->Values.Add("TotalSpawnable", MakeShared<FJsonValueNumber>(CreatureSpawner->GetTotalNumCreatures()));
JCreatureSpawner->Values.Add("Unspawned", MakeShared<FJsonValueNumber>(CreatureSpawner->GetNumUnspawnedCreatures()));
JCreatureSpawner->Values.Add("SpawnDistance", MakeShared<FJsonValueNumber>(CreatureSpawner->GetSpawnDistance()));
JCreatureSpawner->Values.Add("SpawnRadius", MakeShared<FJsonValueNumber>(CreatureSpawner->GetSpawnRadius()));
JCreatureSpawner->Values.Add("RespawnTimeInDays", MakeShared<FJsonValueNumber>(CreatureSpawner->mRespawnTimeIndays));
JCreatureSpawner->Values.Add("CanSpawnDay", MakeShared<FJsonValueBoolean>(CreatureSpawner->CanSpawnDuringDay()));
JCreatureSpawner->Values.Add("CanSpawnNight", MakeShared<FJsonValueBoolean>(CreatureSpawner->CanSpawnDuringNight()));
JCreatureSpawner->Values.Add("IsNearBase", MakeShared<FJsonValueBoolean>(CreatureSpawner->IsNearBase()));
JCreatureSpawner->Values.Add("IsReadyToSpawn", MakeShared<FJsonValueBoolean>(CreatureSpawner->IsReadyToSpawn()));
JCreatureSpawner->Values.Add("IsSpawnerActive", MakeShared<FJsonValueBoolean>(CreatureSpawner->IsSpawnerActive()));
JCreatureSpawner->Values.Add("IsTimeForCreature", MakeShared<FJsonValueBoolean>(CreatureSpawner->IsTimeForCreature()));
JCreatureSpawner->Values.Add("SpawnableCreature", MakeShared<FJsonValueObject>(JSpawnableCreature));
JCreatureSpawner->Values.Add("features", MakeShared<FJsonValueObject>(getActorFeaturesJSON(CreatureSpawner, TEXT("Creature Spawner"), TEXT("Creature Spawner"))));

OutJsonArray.Add(MakeShared<FJsonValueObject>(JCreatureSpawner));
};
};

void UEnvironment::getSporeFlowers(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray) {

UClass* SporeFlowerClass = AFGSporeFlower::StaticClass();
TArray<AActor*> FoundActors;

UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), SporeFlowerClass, FoundActors);
for (AActor* SporeFlowerActor : FoundActors) {

AFGSporeFlower* SporeFlower = Cast<AFGSporeFlower>(SporeFlowerActor);

TSharedPtr<FJsonObject> JSporeFlower = CreateBaseJsonObject(SporeFlower);

AFicsitRemoteMonitoring* ModSubsystem = AFicsitRemoteMonitoring::Get(WorldContext->GetWorld());
fgcheck(ModSubsystem);

FString State;
FString GasState;
bool bIsSignificant;
bool bIsDead;

ModSubsystem->SporeFlower_BIE(SporeFlower, State, GasState, bIsSignificant, bIsDead);

JSporeFlower->Values.Add("ClassName", MakeShared<FJsonValueString>(UKismetSystemLibrary::GetClassDisplayName(SporeFlower->GetClass())));
JSporeFlower->Values.Add("location", MakeShared<FJsonValueObject>(getActorJSON(SporeFlower)));
JSporeFlower->Values.Add("State", MakeShared<FJsonValueString>(State));
JSporeFlower->Values.Add("GasState", MakeShared<FJsonValueString>(GasState));
JSporeFlower->Values.Add("Significant", MakeShared<FJsonValueBoolean>(bIsSignificant));
JSporeFlower->Values.Add("Dead", MakeShared<FJsonValueBoolean>(bIsDead));
JSporeFlower->Values.Add("features", MakeShared<FJsonValueObject>(getActorFeaturesJSON(SporeFlower, TEXT("Spore Flower"), TEXT("Spore Flower"))));

OutJsonArray.Add(MakeShared<FJsonValueObject>(JSporeFlower));
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,4 @@ void UPlayerLibrary::getCreatures(UObject* WorldContext, FRequestData RequestDat

OutJsonArray.Add(MakeShared<FJsonValueObject>(JCreature));
};
};

void UPlayerLibrary::getHazards(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray) {

UClass* SporeFlowerClass = AFGSporeFlower::StaticClass();
TArray<AActor*> FoundActors;

UGameplayStatics::GetAllActorsOfClass(WorldContext->GetWorld(), SporeFlowerClass, FoundActors);
for (AActor* SporeFlowerActor : FoundActors) {

AFGSporeFlower* SporeFlower = Cast<AFGSporeFlower>(SporeFlowerActor);

TSharedPtr<FJsonObject> JSporeFlower = CreateBaseJsonObject(SporeFlower);

AFicsitRemoteMonitoring* ModSubsystem = AFicsitRemoteMonitoring::Get(WorldContext->GetWorld());
fgcheck(ModSubsystem);

FString State;
FString GasState;
bool bIsSignificant;
bool bIsDead;

ModSubsystem->SporeFlower_BIE(SporeFlower, State, GasState, bIsSignificant, bIsDead);

JSporeFlower->Values.Add("ClassName", MakeShared<FJsonValueString>(UKismetSystemLibrary::GetClassDisplayName(SporeFlower->GetClass())));
JSporeFlower->Values.Add("location", MakeShared<FJsonValueObject>(getActorJSON(SporeFlower)));
JSporeFlower->Values.Add("State", MakeShared<FJsonValueString>(State));
JSporeFlower->Values.Add("GasState", MakeShared<FJsonValueString>(GasState));
JSporeFlower->Values.Add("Significant", MakeShared<FJsonValueBoolean>(bIsSignificant));
JSporeFlower->Values.Add("Dead", MakeShared<FJsonValueBoolean>(bIsDead));
JSporeFlower->Values.Add("features", MakeShared<FJsonValueObject>(getActorFeaturesJSON(SporeFlower, TEXT("Spore Flower"), TEXT("Spore Flower"))));

OutJsonArray.Add(MakeShared<FJsonValueObject>(JSporeFlower));
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,15 @@ void UResources::getExtractor(UObject* WorldContext, FRequestData RequestData, T

float CurrentProd = Productivity * MaxProd;

TSharedPtr<FJsonObject> JProduct = GetItemValueObject(ResourceClass->GetResourceClass(), ExtractorInventory->GetNumItems(ItemClass), Extractor->GetFluidInventoryStackSizeScalar());
// GetNumItems() asserts mInventoryStacks.Num() > 0 ("Inventory need to be
// initialized before use"), so an extractor whose output inventory has not
// been initialized yet - e.g. while the world is still streaming in - takes
// the whole game down. GetSizeLinear() reads the same array without asserting.
const int32 NumItems = (IsValid(ExtractorInventory) && ExtractorInventory->GetSizeLinear() > 0)
? ExtractorInventory->GetNumItems(ItemClass)
: 0;

TSharedPtr<FJsonObject> JProduct = GetItemValueObject(ResourceClass->GetResourceClass(), NumItems, Extractor->GetFluidInventoryStackSizeScalar());
JProduct->Values.Add("CurrentProd", MakeShared<FJsonValueNumber>(CurrentProd));
JProduct->Values.Add("MaxProd", MakeShared<FJsonValueNumber>(MaxProd));
JProduct->Values.Add("ProdPercent", MakeShared<FJsonValueNumber>(100 * UKismetMathLibrary::SafeDivide(CurrentProd, MaxProd)));
Expand Down Expand Up @@ -314,7 +322,10 @@ void UResources::getFrackingActivator(UObject* WorldContext, FRequestData Reques
const float Productivity = SatelliteExtractor->GetProductivity();
const UFGInventoryComponent* ExtractorInventory = SatelliteExtractor->GetOutputInventory();

const float NumItems = ExtractorInventory->GetNumItems(ItemClass);
// Same uninitialised-inventory assert as getExtractor above.
const float NumItems = (IsValid(ExtractorInventory) && ExtractorInventory->GetSizeLinear() > 0)
? ExtractorInventory->GetNumItems(ItemClass)
: 0;
BaseNumItems += NumItems;
float CurrentProd = Productivity * MaxProd;

Expand Down
17 changes: 13 additions & 4 deletions Source/FicsitRemoteMonitoring/Private/FicsitRemoteMonitoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Endpoints/Travel/Trains.h"
#include "Endpoints/Travel/Vehicles.h"
#include "Endpoints/World/Communication.h"
#include "Endpoints/World/Environment.h"
#include "Endpoints/World/EventsLibrary.h"
#include "Endpoints/World/Inventory.h"
#include "Endpoints/World/PlayerLibrary.h"
Expand Down Expand Up @@ -756,13 +757,16 @@ void AFicsitRemoteMonitoring::InitAPIRegistry()
RegisterEndpoint(FAPIEndpoint("GET", "getEncoder", &UFactoryLibrary::getEncoder));
RegisterEndpoint(FAPIEndpoint("GET", "getExplorationSink", &USession::getExplorationSink));
RegisterEndpoint(FAPIEndpoint("GET", "getExplorer", &UVehicles::getExplorer).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getExtractor", &UResources::getExtractor));
// RequiresGameThread: calls AFGBuildableFactory::GetProductivity(), which
// check()s IsInGameThread() and crashes when served off the uWS event loop.
RegisterEndpoint(FAPIEndpoint("GET", "getExtractor", &UResources::getExtractor).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getFactoryCart", &UVehicles::getFactoryCart).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getFoundry", &UFactoryLibrary::getFoundry));
RegisterEndpoint(FAPIEndpoint("GET", "getFrackingActivator", &UResources::getFrackingActivator));
// RequiresGameThread: same GetProductivity() game-thread check as getExtractor.
RegisterEndpoint(FAPIEndpoint("GET", "getFrackingActivator", &UResources::getFrackingActivator).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getFuelGenerator", &UPower::getFuelGenerator));
RegisterEndpoint(FAPIEndpoint("GET", "getGeothermalGenerator", &UPower::getGeothermalGenerator));
RegisterEndpoint(FAPIEndpoint("GET", "getHazards", &UPlayerLibrary::getHazards).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getHazards", &UEnvironment::getHazards).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getHUBTerminal", &USupport::getHubTerminal).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getHyperEntrance", &UHypertubes::getHyperEntrance));
RegisterEndpoint(FAPIEndpoint("GET", "getHypertube", &UHypertubes::getHypertube));
Expand All @@ -780,7 +784,10 @@ void AFicsitRemoteMonitoring::InitAPIRegistry()
RegisterEndpoint(FAPIEndpoint("GET", "getPower", &UPower::getPower));
RegisterEndpoint(FAPIEndpoint("GET", "getPowerSlug", &UResources::getPowerSlug).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getPowerUsage", &UPower::getPowerUsage));
RegisterEndpoint(FAPIEndpoint("GET", "getProdStats", &USession::getProdStats));
// RequiresGameThread: walks every manufacturer/extractor/generator calling
// GetProductivity(), which check()s IsInGameThread(). This was the most
// frequent startup crash - the web UI polls it on a timer.
RegisterEndpoint(FAPIEndpoint("GET", "getProdStats", &USession::getProdStats).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getPump", &ULogistics::getPump));
RegisterEndpoint(FAPIEndpoint("GET", "getRadarTower", &USupport::getRadarTower));
RegisterEndpoint(FAPIEndpoint("GET", "getRecipes", &UResearch::getRecipes).RequiresGameThread());
Expand All @@ -791,7 +798,9 @@ void AFicsitRemoteMonitoring::InitAPIRegistry()
RegisterEndpoint(FAPIEndpoint("GET", "getResourceSink", &USession::getResourceSink));
RegisterEndpoint(FAPIEndpoint("GET", "getResourceSinkBuilding", &USupport::getResourceSinkBuilding));
RegisterEndpoint(FAPIEndpoint("GET", "getResourceWell", &UResources::getResourceWell).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getSpawners", &UEnvironment::getSpawners).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getSplitterMerger", &ULogistics::getSplitterMerger));
RegisterEndpoint(FAPIEndpoint("GET", "getSporeFlowers", &UEnvironment::getSporeFlowers).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getSessionInfo", &USession::getSessionInfo).RequiresGameThread().UseFirstObject());
RegisterEndpoint(FAPIEndpoint("GET", "getSchematics", &UResearch::getSchematics).RequiresGameThread());
RegisterEndpoint(FAPIEndpoint("GET", "getSinkList", &USession::getSinkList).RequiresGameThread());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,23 @@ TSharedPtr<FJsonObject> URemoteMonitoringLibrary::getActorJSON(AActor* Actor) {

TSharedPtr<FJsonObject> JLibrary = MakeShared<FJsonObject>();

long double primaryX = Actor->GetActorLocation().X;
long double primaryY = Actor->GetActorLocation().Y;
long double primaryZ = Actor->GetActorLocation().Z;

const long double primaryX = Actor->GetActorLocation().X;
const long double primaryY = Actor->GetActorLocation().Y;
const long double primaryZ = Actor->GetActorLocation().Z;
const long double pitch = Actor->GetActorRotation().Pitch;

// UE rotations range from -180 to 180 with zero as "forward" and negative values "left".
// In Satisfactory this results in a rotation of zero being due east.
// FRM will normalise this to a range of 0 <= x < 360 with zero as due north.
long double rotation = Actor->GetActorRotation().Yaw;
rotation += 450;
rotation = fmod(rotation, 360);

JLibrary->Values.Add("x", MakeShared<FJsonValueNumber>(primaryX));
JLibrary->Values.Add("y", MakeShared<FJsonValueNumber>(primaryY));
JLibrary->Values.Add("z", MakeShared<FJsonValueNumber>(primaryZ));
JLibrary->Values.Add("rotation", MakeShared<FJsonValueNumber>(rotation));
JLibrary->Values.Add("pitch", MakeShared<FJsonValueNumber>(pitch));

return JLibrary;

Expand Down
16 changes: 16 additions & 0 deletions Source/FicsitRemoteMonitoring/Public/Endpoints/World/Environment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include "CoreMinimal.h"
#include "RemoteMonitoringLibrary.h"
#include "Environment.generated.h"

UCLASS()
class FICSITREMOTEMONITORING_API UEnvironment : public URemoteMonitoringLibrary
{
GENERATED_BODY()

public:
static void getHazards(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getSpawners(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getSporeFlowers(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ class FICSITREMOTEMONITORING_API UPlayerLibrary : public URemoteMonitoringLibrar
static void getPlayer(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getDoggo(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getCreatures(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
static void getHazards(UObject* WorldContext, FRequestData RequestData, TArray<TSharedPtr<FJsonValue>>& OutJsonArray);
};
Loading