Skip to content

Commit

Permalink
Allow queuing of targets
Browse files Browse the repository at this point in the history
  • Loading branch information
netniV committed Nov 11, 2024
1 parent 9e9555c commit 979c207
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 89 deletions.
3 changes: 0 additions & 3 deletions example_community_patch_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ hotkeys_extended = true
use_scopely_hotkeys = false

[graphics]
# This is an option that can be enabled to try and keep a more 'useable' UI scale size when resizing the Game Window, defaults to false
adjust_scale_res = false

# Allow borderless full screen mode, set to false to disable
borderless_fullscreen_f11 = true

Expand Down
2 changes: 1 addition & 1 deletion mods/src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@ void Config::Load()
this->ui_scale_viewer = get_config_or_default(config, parsed, "graphics", "ui_scale_viewer", 1.0f);
this->zoom = get_config_or_default(config, parsed, "graphics", "zoom", 2500.f);
this->free_resize = get_config_or_default(config, parsed, "graphics", "free_resize", true);
this->adjust_scale_res = get_config_or_default(config, parsed, "graphics", "adjust_scale_res", false);
this->keyboard_zoom_speed = get_config_or_default(config, parsed, "graphics", "keyboard_zoom_speed", 350.0f);

if (this->enable_experimental) {
Expand Down Expand Up @@ -497,6 +496,7 @@ void Config::Load()

parse_config_shortcut(config, parsed, "action_primary", GameFunction::ActionPrimary, "SPACE");
parse_config_shortcut(config, parsed, "action_secondary", GameFunction::ActionSecondary, "R");
parse_config_shortcut(config, parsed, "action_queue", GameFunction::ActionQueue, "V");
parse_config_shortcut(config, parsed, "action_view", GameFunction::ActionView, "V");
parse_config_shortcut(config, parsed, "action_recall", GameFunction::ActionRecall, "R");
parse_config_shortcut(config, parsed, "action_recall_cancel", GameFunction::ActionRecallCancel, "SPACE");
Expand Down
1 change: 1 addition & 0 deletions mods/src/patches/gamefunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum GameFunction {
UiViewerScaleDown,
ActionPrimary,
ActionSecondary,
ActionQueue,
ActionView,
ActionRecall,
ActionRecallCancel,
Expand Down
54 changes: 48 additions & 6 deletions mods/src/patches/parts/hotkeys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "prime/MissionsObjectViewerWidget.h"
#include "prime/StarNodeObjectViewerWidget.h"

#include "prime/ActionQueueManager.h"
#include "prime/ActionRequirement.h"
#include "prime/AnimatedRewardsScreenViewController.h"
#include "prime/BookmarksManager.h"
Expand Down Expand Up @@ -56,6 +57,16 @@ void GotoSection(SectionID sectionID, void* screen_data = nullptr);
bool CanHideViewers();
bool DidHideViewers();

bool MoveOfficerCanvas(bool goLeft)
{
auto const canvas = ScreenManager::GetTopCanvas(true);
if (strcmp(((Il2CppObject*)(canvas))->klass->name, "OfficerShowcase_Canvas") == 0) {
// canvas->transform->Get
}

return false;
}

void ScreenManager_Update_Hook(auto original, ScreenManager* _this)
{
Key::ResetCache();
Expand Down Expand Up @@ -168,7 +179,23 @@ void ScreenManager_Update_Hook(auto original, ScreenManager* _this)
chat_manager->OpenChannel(ChatChannelCategory::Alliance, ChatViewMode::Fullscreen);
}
}
} else if (MapKey::IsDown(GameFunction::ShowQTrials)) {
}

if (MapKey::IsDown(GameFunction::MoveLeft)) {
auto const result = MoveOfficerCanvas(true);
if (result) {
return;
}
}

if (MapKey::IsDown(GameFunction::MoveRight)) {
auto const result = MoveOfficerCanvas(false);
if (result) {
return;
}
}

if (MapKey::IsDown(GameFunction::ShowQTrials)) {
return GotoSection(SectionID::ChallengeSelection);
} else if (MapKey::IsDown(GameFunction::ShowBookmarks)) {
auto bookmark_manager = BookmarksManager::Instance();
Expand Down Expand Up @@ -300,7 +327,7 @@ void ScreenManager_Update_Hook(auto original, ScreenManager* _this)

if (MapKey::IsDown(GameFunction::ActionPrimary) || MapKey::IsDown(GameFunction::ActionSecondary)
|| MapKey::IsDown(GameFunction::ActionRecall) || MapKey::IsDown(GameFunction::ActionRepair)
|| force_space_action_next_frame) {
|| MapKey::IsDown(GameFunction::ActionQueue) || force_space_action_next_frame) {
if (Hub::IsInSystemOrGalaxyOrStarbase() && !Hub::IsInChat() && !Key::IsInputFocused()) {
auto fleet_bar = ObjectFinder<FleetBarViewController>::Get();
if (fleet_bar) {
Expand Down Expand Up @@ -494,21 +521,34 @@ bool DidExecuteRepair(FleetBarViewController* fleet_bar)
FleetState::Repairing);
}

void CanQueueTarget(FleetPlayerData* fleet) {}

void ExecuteSpaceAction(FleetBarViewController* fleet_bar)
{
auto fleet_controller = fleet_bar->_fleetPanelController;
auto fleet = fleet_controller->fleet;

auto action_queue = ActionQueueManager::Instance();

auto has_primary = MapKey::IsDown(GameFunction::ActionPrimary) || force_space_action_next_frame;
auto has_repair = MapKey::IsDown(GameFunction::ActionRepair);
auto has_recall_cancel = MapKey::IsDown(GameFunction::ActionRecallCancel);
auto has_secondary = MapKey::IsDown(GameFunction::ActionSecondary);
auto has_queue = MapKey::IsDown(GameFunction::ActionQueue) && action_queue->CanAddToQueue(fleet);
auto has_recall =
MapKey::IsDown(GameFunction::ActionRecall) && (!Config::Get().disable_preview_recall || !CanHideViewers());

auto fleet_controller = fleet_bar->_fleetPanelController;
auto fleet = fleet_controller->fleet;

if (has_recall_cancel
&& (fleet->CurrentState == FleetState::WarpCharging || fleet->CurrentState == FleetState::Warping)) {
fleet_controller->CancelWarpClicked();
} else if (has_queue) {
auto fleets_manager = FleetsManager::Instance();
if (fleets_manager != nullptr) {
auto target = fleets_manager->targetFleetData;
if (target != nullptr) {
action_queue->AddToQueue(target->ID);
}
}
} else {
auto all_pre_scan_widgets = ObjectFinder<PreScanTargetWidget>::GetAll();
for (auto pre_scan_widget : all_pre_scan_widgets) {
Expand All @@ -526,7 +566,9 @@ void ExecuteSpaceAction(FleetBarViewController* fleet_bar)
return mine_object_viewer_widget->MineClicked();
}
} else {
if (has_secondary) {
if (has_queue) {

} else if (has_secondary) {
return pre_scan_widget->_scanEngageButtonsWidget->OnScanButtonClicked();
} else if (has_primary) {
auto armada_object_viewer_widget = ObjectFinder<ArmadaObjectViewerWidget>::Get();
Expand Down
2 changes: 1 addition & 1 deletion mods/src/patches/parts/testing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "prime/DeploymentManager.h"
#include "prime/FleetLocalViewController.h"
#include "prime/FleetsManager.h"
#include "prime/FullScreenChatViewController.h"
#include "prime/Hub.h"
#include "prime/InventoryForPopup.h"
#include "prime/KeyCode.h"
Expand All @@ -18,7 +19,6 @@
#include "prime/SceneManager.h"
#include "prime/ScreenManager.h"
#include <prime/UIBehaviour.h>
#include "prime/FullScreenChatViewController.h"

#include <il2cpp/il2cpp_helper.h>
#include <spud/detour.h>
Expand Down
60 changes: 60 additions & 0 deletions mods/src/prime/ActionQueueManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#pragma once

#include <il2cpp/il2cpp_helper.h>

#include "FleetPlayerData.h"
#include "MonoSingleton.h"

struct ActionQueueManager : MonoSingleton<ActionQueueManager> {
friend struct MonoSingleton<ActionQueueManager>;

public:
bool IsQueueFull(FleetPlayerData* playerData)
{
static auto IsQueueFullMethod =
get_class_helper().GetMethod<bool(ActionQueueManager*, FleetPlayerData*)>("IsQueueFull");
return IsQueueFullMethod(this, playerData);
}

bool IsFleetInQueue(FleetPlayerData* playerData)
{
static auto IsFleetInQueueMethod =
get_class_helper().GetMethod<bool(ActionQueueManager*, FleetPlayerData*)>("IsFleetInQueue");

return IsFleetInQueueMethod(this, playerData);
}

bool IsQueueUnlocked()
{
static auto IsQueueUnlockedMethod = get_class_helper().GetMethod<bool(ActionQueueManager*)>("IsQueueUnlocked");
return IsQueueUnlockedMethod(this);
}

bool CanAddToQueue(FleetPlayerData* playerData)
{
if (IsQueueUnlocked()) {
if (!IsQueueFull(playerData)) {
if (!IsFleetInQueue(playerData)) {
return true;
}
}
}

return false;
}

void AddToQueue(long targetId)
{
static auto AddToQueueMethod = get_class_helper().GetMethod<void(ActionQueueManager*, long)>("AddActionToQueue");
if (AddToQueueMethod != nullptr) {
AddToQueueMethod(this, targetId);
}
}

private:
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper = il2cpp_get_class_helper("Assembly-CSharp", "Prime.ActionQueue", "ActionQueueManager");
return class_helper;
}
};
76 changes: 2 additions & 74 deletions mods/src/prime/BattleTargetData.h
Original file line number Diff line number Diff line change
@@ -1,79 +1,7 @@
#pragma once

#include <il2cpp/il2cpp_helper.h>

enum class HullType {
Any = -1,
Destroyer = 0,
Survey = 1,
Explorer = 2,
Battleship = 3,
Defense = 4,
ArmadaTarget = 5
};

enum class DeployedFleetType {
Nonexistent,
Player,
Marauder,
NpcInstantiated,
Sentinel,
Alliance,
};

struct HullSpec {
public:
__declspec(property(get = __get_Id)) long Id;
__declspec(property(get = __get_Type)) HullType Type;

private:
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper =
il2cpp_get_class_helper("Digit.Client.PrimeLib.Runtime", "Digit.PrimeServer.Models", "HullSpec");
return class_helper;
}

public:
long __get_Id()
{
static auto field = get_class_helper().GetField("id_").offset();
return *(long*)((char*)this + field);
}

HullType __get_Type()
{
static auto field = get_class_helper().GetProperty("Type");
return *field.Get<HullType>(this);
}
};

struct FleetDeployedData {
public:
__declspec(property(get = __get_Hull)) HullSpec* Hull;
__declspec(property(get = __get_FleetType)) DeployedFleetType FleetType;

private:
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper =
il2cpp_get_class_helper("Digit.Client.PrimeLib.Runtime", "Digit.PrimeServer.Models", "FleetDeployedData");
return class_helper;
}

public:
HullSpec* __get_Hull()
{
static auto field = get_class_helper().GetProperty("Hull");
return field.GetRaw<HullSpec>(this);
}

DeployedFleetType __get_FleetType()
{
static auto field = get_class_helper().GetProperty("FleetType");
return *field.Get<DeployedFleetType>(this);
}
};
#include "FleetDeployedData.h"

struct BattleTargetData {
public:
Expand All @@ -93,4 +21,4 @@ struct BattleTargetData {
static auto field = get_class_helper().GetField("TargetFleetDeployedData").offset();
return *(FleetDeployedData**)((char*)this + field);
}
};
};
6 changes: 3 additions & 3 deletions mods/src/prime/DeploymentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include "CallbackContainer.h"
#include "MonoSingleton.h"
#include "Vector3.h"
#include "FleetPlayerData.h"
#include "FleetDeployedData.h"

#include <il2cpp/il2cpp_helper.h>

struct FleetPlayerData;
struct FleetDeployedData;
class DeploymentService
{
public:
Expand Down Expand Up @@ -70,4 +70,4 @@ struct DeploymentManger : MonoSingleton<DeploymentManger> {
static auto class_helper = il2cpp_get_class_helper("Assembly-CSharp", "", "DeploymentManager");
return class_helper;
}
};
};
47 changes: 47 additions & 0 deletions mods/src/prime/FleetDeployedData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <il2cpp/il2cpp_helper.h>
#include "HullSpec.h"

enum class DeployedFleetType {
Nonexistent,
Player,
Marauder,
NpcInstantiated,
Sentinel,
Alliance,
};

struct FleetDeployedData {
public:
__declspec(property(get = __get_ID)) long ID;
__declspec(property(get = __get_Hull)) HullSpec* Hull;
__declspec(property(get = __get_FleetType)) DeployedFleetType FleetType;

private:
static IL2CppClassHelper& get_class_helper()
{
static auto class_helper =
il2cpp_get_class_helper("Digit.Client.PrimeLib.Runtime", "Digit.PrimeServer.Models", "FleetDeployedData");
return class_helper;
}

public:
long __get_ID()
{
static auto field = get_class_helper().GetProperty("ID");
return *field.Get<long>(this);
}

HullSpec* __get_Hull()
{
static auto field = get_class_helper().GetProperty("Hull");
return field.GetRaw<HullSpec>(this);
}

DeployedFleetType __get_FleetType()
{
static auto field = get_class_helper().GetProperty("FleetType");
return *field.Get<DeployedFleetType>(this);
}
};
2 changes: 2 additions & 0 deletions mods/src/prime/FleetLocalViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct FleetLocalViewController {
static auto CancelWarpClicked = get_class_helper().GetMethod<void(FleetLocalViewController*)>("CancelWarpClicked");
if (CancelWarpClicked != nullptr) {
CancelWarpClicked(this);
} else {

}
}

Expand Down
3 changes: 2 additions & 1 deletion mods/src/prime/FleetPlayerData.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "BattleTargetData.h"
#include "HullSpec.h"
#include "RecallRequirement.h"
#include "CanRepairRequirement.h"

Expand Down Expand Up @@ -87,4 +88,4 @@ struct FleetPlayerData {
static auto field = get_class_helper().GetProperty("Id");
return *field.Get<uint64_t>(this);
}
};
};
Loading

0 comments on commit 979c207

Please sign in to comment.