Skip to content

Commit

Permalink
update to resolve tame issue
Browse files Browse the repository at this point in the history
  • Loading branch information
antihax committed May 4, 2022
1 parent 1c19883 commit eda7a8a
Show file tree
Hide file tree
Showing 14 changed files with 449 additions and 32 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json
9 changes: 5 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"parser": "flow",
"trailingComma": "all",
"trailingComma": "none",
"useTabs": true,
"printWidth": 100,
"printWidth": 200,
"semi": true,
"singleQuote": true,
"doubleQuote": true,
"bracketSpacing": false,
"bracketSameLine": true
"bracketSameLine": true,
"quoteProps": "preserve"
}
151 changes: 151 additions & 0 deletions DumpResources/ChangeAnything/ChangeAnything.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#include <API/Atlas/Atlas.h>
#include "json.hpp"
#include <filesystem>
#include <fstream>
#pragma comment(lib, "AtlasApi.lib")

DECLARE_HOOK(AShooterGameMode_BeginPlay, void, AShooterGameMode*);
DECLARE_HOOK(AShooterGameMode_InitOptions, void, AShooterGameMode*, FString);

void Load() {
Log::Get().Init("Change Anything");
ArkApi::GetHooks().SetHook("AShooterGameMode.BeginPlay", &Hook_AShooterGameMode_BeginPlay, &AShooterGameMode_BeginPlay_original);
ArkApi::GetHooks().SetHook("AShooterGameMode.InitOptions", &Hook_AShooterGameMode_InitOptions, &AShooterGameMode_InitOptions_original);
}

void Unload() {
ArkApi::GetHooks().DisableHook("AShooterGameMode.BeginPlay", &Hook_AShooterGameMode_BeginPlay);
ArkApi::GetHooks().DisableHook("AShooterGameMode.InitOptions", &Hook_AShooterGameMode_InitOptions);
}

template<typename T>
T Get(UProperty* This, UObject* object) {
if (sizeof(T) != This->ElementSizeField())
throw std::invalid_argument("Expected size does not match property size.");
return *((T*)(object + This->Offset_InternalField()));
}

template<typename T>
void Set(UProperty* This, UObject* object, T value)
{
if (sizeof(T) != This->ElementSizeField())
throw std::invalid_argument("Expected size does not match property size.");
*((T*)(object + This->Offset_InternalField())) = value;
}

nlohmann::json getVariableData(UObject* o, UClass* c, UProperty* p) {
nlohmann::json json;
auto type = p->ClassField()->NameField().ToString().ToString();
if (c->NameField().ToString().Compare(FString("AutoFarm_C"))) {
if (p->NameField().ToString().ToString() == "HarvestInterval")
Set<float>(p, o, 2.0f);
else if (p->NameField().ToString().ToString() == "HarvestRadius")
Set<float>(p, o, 50000.0f);
else if (p->NameField().ToString().ToString() == "HarvestQuantity")
Set<int>(p, o, 50);
}
if (c->NameField().ToString().ToString() == "Storehouse_C" || c->NameField().ToString().ToString() == "PrimalStructureStorehouse") {
if (p->NameField().ToString().ToString() == "CollectionPercentage") {
Log::GetLog()->info("Class: {} Object: {}", c->NameField().ToString().ToString(), o->NameField().ToString().ToString());
Set<float>(p, o, 0.90f);
}
else if (p->NameField().ToString().ToString() == "TransportInterval")
Set<float>(p, o, 2.0f);
}

if (type == "BoolProperty") {
auto v = Get<bool>(p, o);
return { {"type", type}, {"value" , v} };
}
else if (type == "FloatProperty") {
auto v = Get<float>(p, o);
return { {"type", type}, {"value" , v} };
}
else if (type == "DoubleProperty") {
auto v = Get<double>(p, o);
return { {"type", type}, {"value" , v} };
}
else if (type == "UInt64Property") {
auto v = Get<uint64>(p, o);
return { {"type", type}, {"value" , v} };
}
else if (type == "Int64Property") {
auto v = Get<int64>(p, o);
return { {"type", type}, {"value" , v} };
}
else if (type == "UInt32Property") {
auto v = Get<uint32>(p, o);
return { {"type", type}, {"value" , v} };
}
else if (type == "Int32Property") {
auto v = Get<int32>(p, o);
return { {"type", type}, {"value" , v} };
}
else if (type == "IntProperty") {
auto v = Get<int>(p, o);
return { {"type", type}, {"value" , v} };
}
else if (type == "ByteProperty") {
auto v = Get<byte>(p, o);
return { {"type", type}, {"value" , v} };
}
else if (type == "StrProperty") {
auto v = Get<FString>(p, o);
return { {"type", type}, {"value" , v.ToString()} };
}
else if (type == "NameProperty") {
auto v = Get<FName>(p, o);
return { {"type", type}, {"value" , v.ToString().ToString()} };
}
else {
return { {"type", type} };
}
}

nlohmann::json searchObjects() {
nlohmann::json json = {};
TArray<UObject*> objects;
Globals::GetObjectsOfClass(UObject::GetPrivateStaticClass(), &objects, true, EObjectFlags::RF_NoFlags);
for (auto o : objects) {
auto c = o->ClassField();
json[o->NameField().ToString().ToString()] = { {"class", c->NameField().ToString().ToString()}, {"properties", {} } };

if (c != NULL) {
auto p = c->PropertyLinkField();
while (p != NULL) {
auto v = getVariableData(o, c, p);
json[o->NameField().ToString().ToString()]["properties"][p->NameField().ToString().ToString()] = v;
p = p->PropertyLinkNextField();
}
}
}
return json;
}

void Hook_AShooterGameMode_BeginPlay(AShooterGameMode* This) {
auto j = searchObjects();
std::filesystem::create_directory("changeanything");
std::ofstream file("changeanything/objects.json");
file << std::setw(2) << j;
file.flush();
file.close();
AShooterGameMode_BeginPlay_original(This);
}


void Hook_AShooterGameMode_InitOptions(AShooterGameMode* This, FString Options) {
AShooterGameMode_InitOptions_original(This, Options);
}

BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call, LPVOID /*lpReserved*/) {
switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
Load();
break;
case DLL_PROCESS_DETACH:
Unload();
break;
}

return TRUE;
}
22 changes: 22 additions & 0 deletions DumpResources/ChangeAnything/ChangeAnything.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ChangeAnything.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
110 changes: 110 additions & 0 deletions DumpResources/ChangeAnything/ChangeAnything.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ChangeAnything.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{2AC92E8D-1885-4E8B-80EA-4980CE657F66}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ChangeAnything</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>i:\atlas\ARK-Server-API\version\Core\Public;$(IncludePath)</IncludePath>
<LibraryPath>i:\atlas\ARK-Server-API\out_lib;$(LibraryPath)</LibraryPath>
<CodeAnalysisRuleSet>NativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<LibraryPath>f:\atlas\ARK-Server-API\out_lib;$(LibraryPath)</LibraryPath>
<IncludePath>f:\atlas\ARK-Server-API\version\Core\Public;$(IncludePath)</IncludePath>
<CodeAnalysisRuleSet>NativeRecommendedRules.ruleset</CodeAnalysisRuleSet>
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;ChangeAnything_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<LanguageStandard>stdcpp17</LanguageStandard>
<EnablePREfast>false</EnablePREfast>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<PostBuildEvent>
<Command>copy i:\atlas\ATLAS-Plugins\ChangeAnything\x64\Release\ChangeAnything.dll i:\atlas\server\ShooterGame\Binaries\Win64\AtlasApi\Plugins\ChangeAnything</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>false</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;ChangeAnything_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<LanguageStandard>stdcpp17</LanguageStandard>
<EnablePREfast>false</EnablePREfast>
<OmitFramePointers>false</OmitFramePointers>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<DelayLoadDLLs>Permissions.dll</DelayLoadDLLs>
</Link>
<PostBuildEvent>
<Command>mkdir $(SolutionDir)server\ShooterGame\Binaries\Win64\AtlasApi\Plugins\$(TargetName)
copy $(OutDir)$(TargetFileName) $(SolutionDir)server\ShooterGame\Binaries\Win64\AtlasApi\Plugins\$(TargetName)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
18 changes: 18 additions & 0 deletions DumpResources/ChangeAnything/configs/PdbConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"structures": [
"UShooterGameInstance",
"AShooterGameMode",
"ANPCZoneManager",
"ADiscoveryZone",
"ABiomeZoneVolume",
"UInstancedStaticMeshComponent",
"ASupplyCrateSpawningVolume",
"AFoliageAttachmentOverrideVolume",
"UPrimalHarvestingComponent",
"UPrimalItem",
"UObject",
"AActor",
"FVector"
],
"functions": ["GetObjectsOfClass"]
}
6 changes: 6 additions & 0 deletions DumpResources/DumpResources.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ForceOldStructureChecks", "
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DebugTools", "DebugTools\DebugTools.vcxproj", "{1D8A1AAA-44A0-4087-A68D-D9D143BD2F73}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChangeAnything", "ChangeAnything\ChangeAnything.vcxproj", "{2AC92E8D-1885-4E8B-80EA-4980CE657F66}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -29,6 +31,10 @@ Global
{1D8A1AAA-44A0-4087-A68D-D9D143BD2F73}.Debug|x64.Build.0 = Debug|x64
{1D8A1AAA-44A0-4087-A68D-D9D143BD2F73}.Release|x64.ActiveCfg = Release|x64
{1D8A1AAA-44A0-4087-A68D-D9D143BD2F73}.Release|x64.Build.0 = Release|x64
{2AC92E8D-1885-4E8B-80EA-4980CE657F66}.Debug|x64.ActiveCfg = Debug|x64
{2AC92E8D-1885-4E8B-80EA-4980CE657F66}.Debug|x64.Build.0 = Debug|x64
{2AC92E8D-1885-4E8B-80EA-4980CE657F66}.Release|x64.ActiveCfg = Release|x64
{2AC92E8D-1885-4E8B-80EA-4980CE657F66}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Loading

0 comments on commit eda7a8a

Please sign in to comment.