Skip to content

Commit

Permalink
Added a "Game.DeleteForgeItem" command (bind it to a key using the "b…
Browse files Browse the repository at this point in the history
…ind" command)
  • Loading branch information
Shockfire committed Jul 15, 2015
1 parent 5e9541f commit 61e497c
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ add_library(ElDorito SHARED
src/Patches/ContentItems.hpp
src/Patches/Core.cpp
src/Patches/Core.hpp
src/Patches/Forge.cpp
src/Patches/Forge.hpp
src/Patches/KeyboardInput.cpp
src/Patches/KeyboardInput.hpp
src/Patches/Logging.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/ElPatches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Patches\ContentItems.hpp"
#include "Patches\PlayerUid.hpp"
#include "Patches\KeyboardInput.hpp"
#include "Patches\Forge.hpp"

#include "Modules\ModuleCamera.hpp"

Expand All @@ -37,6 +38,7 @@ namespace Patches
ContentItems::ApplyAll();
PlayerUid::ApplyAll();
KeyboardInput::ApplyAll();
Forge::ApplyAll();
}

void ApplyOnFirstTick()
Expand Down
9 changes: 9 additions & 0 deletions src/Modules/ModuleGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../Blam/BlamTypes.hpp"
#include "../Blam/Tags/GameEngineSettingsDefinition.hpp"
#include "../Menu.hpp"
#include "../Patches/Forge.hpp"

namespace
{
Expand Down Expand Up @@ -685,6 +686,12 @@ namespace
return true;
}

bool CommandDeleteForgeItem(const std::vector<std::string>& arguments, std::string& returnInfo)
{
Patches::Forge::SignalDelete();
return true;
}

//EXAMPLE:
/*std::string VariableGameNameUpdate(const std::vector<std::string>& Arguments)
{
Expand Down Expand Up @@ -724,6 +731,8 @@ namespace Modules
AddCommand("Version", "version", "Displays the game's version", eCommandFlagsNone, CommandGameVersion);

AddCommand("SetMenuEnabled", "set_menu", "Sets whether the menu is currently open", eCommandFlagsNone, CommandGameSetMenuEnabled);

AddCommand("DeleteForgeItem", "forge_delete", "Delete the Forge item under the crosshairs", eCommandFlagsNone, CommandDeleteForgeItem);

VarMenuURL = AddVariableString("MenuURL", "menu_url", "url(string) The URL of the page you want to load inside the menu", eCommandFlagsArchived, "http://eldewrito.github.io/menu/");

Expand Down
62 changes: 62 additions & 0 deletions src/Patches/Forge.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "Forge.hpp"

#include "../Patch.hpp"

namespace
{
bool shouldDelete = false;
void UpdateForgeInputHook();
}

namespace Patches
{
namespace Forge
{
void ApplyAll()
{
Hook(0x19D482, UpdateForgeInputHook, HookFlags::IsCall).Apply();
}

void SignalDelete()
{
shouldDelete = true;
}
}
}

namespace
{
__declspec(naked) void UpdateForgeInputHook()
{
__asm
{
mov al, shouldDelete
test al, al
jnz del

// Not deleting - just call the original function
push esi
mov eax, 0x59F0E0
call eax
retn 4

del:
mov shouldDelete, 0

// Simulate a Y button press
mov eax, 0x244D1F0 // Controller data
mov byte ptr [eax + 0x9E], 1 // Ticks = 1
and byte ptr [eax + 0x9F], 0xFE // Clear the "handled" flag

// Call the original function
push esi
mov eax, 0x59F0E0
call eax

// Make sure nothing else gets the fake press
mov eax, 0x244D1F0 // Controller data
or byte ptr [eax + 0x9F], 1 // Set the "handled" flag
retn 4
}
}
}
12 changes: 12 additions & 0 deletions src/Patches/Forge.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

namespace Patches
{
namespace Forge
{
void ApplyAll();

// Signal to delete the current item, if any
void SignalDelete();
}
}

0 comments on commit 61e497c

Please sign in to comment.