Skip to content

Commit

Permalink
Improve performance of ObjectFinder by making our own!
Browse files Browse the repository at this point in the history
  • Loading branch information
netniV committed Jan 18, 2024
1 parent 7ec0ede commit 766ecb6
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 47 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
- Add show resarch key ('U')
- Add example configuration file
- Adjust runtime configuration output:
- Rename 'community_patch_settings_parsed.toml' to 'community_patch_runtime.vars' to avoid confusion
- Add a massive comment to top of community_patch_runtimes.vars
- Rename 'community_patch_settings_parsed.toml' to 'community_patch_runtime.vars' to avoid confusion
- Add a massive comment to top of community_patch_runtimes.vars
- Add ui_scale_adjust to allow changes to "step" between ui_scale's
- Make ui_scaleup/ui_scaldown operate like zoom and can now be held
- Add session-based adjustments that last until game is restarted:
- Add toggle cargo views (ALT 1-5)
- Add set zoom preset (SHIFT F1-F5)
- Add toggle cargo views (ALT 1-5)
- Add set zoom preset (SHIFT F1-F5)
- Fix speed issues with ObjectFinder by writing our own

## 0.5.2

Expand All @@ -37,7 +38,7 @@

## 0.4.0

- who knows
- who knows

## 0.3.8

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ add_library(stfc-community-patch SHARED ${TARGET_SRC} ${PATCHES} ${PRIME}
"src/prime/AspectRatioConstraintHandler.h"
"src/prime/RewardsButtonWidget.h"
"src/prime/IEnumerator.h"
"src/prime/LanguageManager.h")
"src/prime/LanguageManager.h" "src/prime/UIBehaviour.h")

set_property(TARGET stfc-community-patch PROPERTY CXX_STANDARD 20)
set_property(TARGET stfc-community-patch PROPERTY CXX_STANDARD_REQUIRED ON)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ E | Zoom In
T | Events
G | Galaxy
H | System
Shift-G | Exterior View
Shfit-H | Interior View
R | When ship selected, recall ship
R | When clicking on mine/player/enemy, perform non-default action (eg, scan)
V | When clicking on mine/player/enemy, toggle view of cargo or default screen
Expand Down Expand Up @@ -138,6 +140,10 @@ The most common problems getting the DLL to work are:
You can verify your configuration by looking at `community_patch_runtime.vars` and/or the
log file `community_patch.log`.

## Support

Tashcan is now retiring from all things STFC but will still be maintaining [Ripper's Corner](https://discord.gg/NA4r3jKWEX) for other things. For STFC Community Mod items, please visit the [STFC Community Mod](https://discord.gg/PrpHgs7Vjs) discord server.

## Disclaimer

This is intended to give people insight and possiblity to add new things for QoL improvements.
Expand Down
82 changes: 47 additions & 35 deletions src/patches/parts/testing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,17 @@
#include "config.h"
#include "utils.h"

#include "prime/BlurController.h"
#include "prime/CallbackContainer.h"
#include "prime/ChatManager.h"
#include "prime/ChatMessageListLocalViewController.h"
#include "prime/ClientModifierType.h"
#include "prime/FleetBarViewController.h"
#include "prime/FleetLocalViewController.h"
#include "prime/FullScreenChatViewController.h"
#include "prime/Hub.h"
#include "prime/InventoryForPopup.h"
#include "prime/KeyCode.h"
#include "prime/MiningObjectViewerWidget.h"
#include "prime/NavigationInteractionUIViewController.h"
#include "prime/ScanEngageButtonsWidget.h"
#include "prime/ScreenManager.h"
#include "prime/AllianceStarbaseObjectViewerWidget.h"
#include "prime/PreScanTargetWidget.h"
#include "prime/ActionRequirement.h"
#include "prime/AllianceStarbaseObjectViewerWidget.h"
#include "prime/AnimatedRewardsScreenViewController.h"
#include "prime/ArmadaObjectViewerWidget.h"
#include "prime/BlurController.h"
#include "prime/BookmarksManager.h"
#include "prime/CallbackContainer.h"
#include "prime/CelestialObjectViewerWidget.h"
#include "prime/ChatManager.h"
#include "prime/ChatMessageListLocalViewController.h"
#include "prime/ClientModifierType.h"
#include "prime/DeploymentManager.h"
#include "prime/EmbassyObjectViewer.h"
#include "prime/FleetBarViewController.h"
Expand All @@ -38,6 +24,7 @@
#include "prime/FullScreenChatViewController.h"
#include "prime/HousingObjectViewerWidget.h"
#include "prime/Hub.h"
#include "prime/InventoryForPopup.h"
#include "prime/KeyCode.h"
#include "prime/MiningObjectViewerWidget.h"
#include "prime/MissionsObjectViewerWidget.h"
Expand All @@ -53,11 +40,12 @@
#include <il2cpp/il2cpp_helper.h>

#include <EASTL/unordered_map.h>
#include <EASTL/vector.h>
#include <EASTL/unordered_set.h>
#include <EASTL/vector.h>

#include <chrono>
#include <iostream>
#include <prime/UIBehaviour.h>

static int i = 0;

Expand Down Expand Up @@ -254,30 +242,52 @@ AppConfig* Model_LoadConfigs(auto original, Model* _this)
return config;
}

std::vector<std::string> tracked_classes;
eastl::unordered_map<Il2CppClass*, eastl::vector<uintptr_t>> tracked_objects;

void* track_ctor(auto original, void* _this) {
auto cls = (Il2CppObject*)_this;
auto &tracked_object_vector = tracked_objects[cls->klass];
tracked_object_vector.emplace_back(uintptr_t(_this));
void* track_ctor(auto original, void* _this)
{
if (_this != nullptr) {
auto cls = (Il2CppObject*)_this;
auto clsName = std::string(cls->klass->name);

spdlog::info("Tracking object {} - {}", clsName, (int)_this);

auto& tracked_object_vector = tracked_objects[cls->klass];
tracked_object_vector.emplace_back(uintptr_t(_this));

if (std::find(tracked_classes.begin(), tracked_classes.end(), clsName) == tracked_classes.end()) {
tracked_classes.emplace_back(clsName);
}
}

return original(_this);
}

void track_destroy(auto original, void* _this)
{
auto cls = (Il2CppObject*)_this;
auto& tracked_object_vector = tracked_objects[cls->klass];
tracked_object_vector.erase_first(uintptr_t(_this));
original(_this);
if (_this != nullptr) {
auto cls = (Il2CppObject*)_this;
auto clsName = std::string(cls->klass->name);

if (std::find(tracked_classes.begin(), tracked_classes.end(), clsName) != tracked_classes.end()) {
spdlog::info("Destroying object {} - {}", clsName, (int)_this);

auto& tracked_object_vector = tracked_objects[cls->klass];
tracked_object_vector.erase_first(uintptr_t(_this));
original(_this);
}
}
}

template<typename T> void TrackObject() {
template <typename T> void TrackObject()
{
static eastl::unordered_set<void*> seen_ctor;
static eastl::unordered_set<void*> seen_destroy;

auto &alliance_widget = T::get_class_helper();
auto ctor = alliance_widget.GetMethod(".ctor");
auto on_destroy = alliance_widget.GetMethod("OnDestroy");
auto& object_class = T::get_class_helper();
auto ctor = object_class.GetMethod(".ctor");
auto on_destroy = object_class.GetMethod("OnDestroy");

if (seen_ctor.find(ctor) == eastl::end(seen_ctor)) {
SPUD_STATIC_DETOUR(ctor, track_ctor);
Expand All @@ -290,7 +300,6 @@ template<typename T> void TrackObject() {
}
}


void InstallTestPatches()
{
auto app_config = il2cpp_get_class_helper("Assembly-CSharp", "Digit.Client.Core", "AppConfig");
Expand All @@ -305,14 +314,17 @@ void InstallTestPatches()
il2cpp_get_class_helper("Digit.Client.PrimeLib.Runtime", "Digit.PrimeServer.Models", "BattleTargetData");
battle_target_data = battle_target_data;

TrackObject<HousingObjectViewerWidget>();
TrackObject<PreScanTargetWidget>();
TrackObject<FleetBarViewController>();
TrackObject<AllianceStarbaseObjectViewerWidget>();
TrackObject<AnimatedRewardsScreenViewController>();
TrackObject<ArmadaObjectViewerWidget>();
TrackObject<CelestialObjectViewerWidget>();
TrackObject<EmbassyObjectViewer>();
TrackObject<FullScreenChatViewController>();
TrackObject<HousingObjectViewerWidget>();
TrackObject<MiningObjectViewerWidget>();
TrackObject<MissionsObjectViewerWidget>();
TrackObject<PreScanTargetWidget>();
TrackObject<HousingObjectViewerWidget>();
TrackObject<FleetBarViewController>();
TrackObject<NavigationInteractionUIViewController>();
TrackObject<StarNodeObjectViewerWidget>();
}
3 changes: 2 additions & 1 deletion src/prime/FullScreenChatViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ class FullScreenChatViewController

private:
friend class ObjectFinder<FullScreenChatViewController>;

public:
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper =
il2cpp_get_class_helper("Assembly-CSharp", "Digit.Prime.Chat", "FullScreenChatViewController");
return class_helper;
}

public:
ChatMessageListLocalViewController* __get__messageList()
{
static auto field = get_class_helper().GetField("_messageList").offset();
Expand Down
5 changes: 3 additions & 2 deletions src/prime/NavigationInteractionUIViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ struct NavigationInteractionUIViewController {
OnSetCourseButtonClick(this);
}

private:
friend class ObjectFinder<NavigationInteractionUIViewController>;
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper =
il2cpp_get_class_helper("Assembly-CSharp", "Digit.Prime.Navigation", "NavigationInteractionUIViewController");
return class_helper;
}

private:
friend class ObjectFinder<NavigationInteractionUIViewController>;
};
7 changes: 4 additions & 3 deletions src/prime/StarNodeObjectViewerWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ struct StarNodeObjectViewerWidget : public Widget<void, StarNodeObjectViewerWidg
InitiateWarp(this);
}

private:
friend class ObjectFinder<StarNodeObjectViewerWidget>;
friend struct Widget<void, StarNodeObjectViewerWidget>;
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper =
il2cpp_get_class_helper("Assembly-CSharp", "Digit.Prime.ObjectViewer", "StarNodeObjectViewerWidget");
return class_helper;
}

private:
friend class ObjectFinder<StarNodeObjectViewerWidget>;
friend struct Widget<void, StarNodeObjectViewerWidget>;
};
12 changes: 12 additions & 0 deletions src/prime/UIBehaviour.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include <il2cpp/il2cpp_helper.h>

struct UIBehaviour {
public:
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper =
il2cpp_get_class_helper("UnityEngine.UI", "UnityEngine.EventSystems", "UIBehaviour");
return class_helper;
}
};

0 comments on commit 766ecb6

Please sign in to comment.