Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
328 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,4 +58,5 @@ ipch/ | |
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
*.vspx | ||
*.vspx | ||
*.opendb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "StdAfx.h" | ||
#include "stdafx.h" | ||
#include "AnimationFile.h" | ||
#include <fstream> | ||
#include <iostream> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 12 additions & 2 deletions
14
SA2ModLoader/LandTableInfo.cpp → libmodutils/LandTableInfo.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "stdafx.h" | ||
#include "Trampoline.h" | ||
|
||
#include <Windows.h> | ||
#include <exception> | ||
#include <ninja.h> // for typedefs | ||
#include <ModLoader/MemAccess.h> | ||
|
||
/// <summary> | ||
/// Initializes a new <see cref="Trampoline" />, allowing you to replace functions and still call the original code. | ||
/// </summary> | ||
/// <param name="start">Start offset (address of function).</param> | ||
/// <param name="end">End offset.</param> | ||
/// <param name="func">Your detour function.</param> | ||
Trampoline::Trampoline(size_t start, size_t end, DetourFunction func) : | ||
target(nullptr), detour(nullptr), codeData(nullptr), originalSize(0), codeSize(0) | ||
{ | ||
if (start > end) | ||
throw std::exception("Start address cannot exceed end address."); | ||
|
||
if (end - start < 5) | ||
throw std::exception("Length cannot be less than 5 bytes."); | ||
|
||
target = (void*)start; | ||
detour = func; | ||
originalSize = end - start; | ||
codeSize = originalSize + 5; | ||
|
||
// Copy original instructions | ||
codeData = VirtualAlloc(nullptr, codeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); | ||
if (codeData == nullptr) | ||
throw std::exception("VirtualAlloc failure"); | ||
|
||
// ReadProcessMemory maybe? | ||
memcpy(codeData, target, originalSize); | ||
|
||
// Append jump (terribly) | ||
WriteJump((&((Uint8*)codeData)[originalSize]), (void*)end); | ||
|
||
// NOP | ||
std::vector<Uint8> nop(originalSize, 0x90); | ||
WriteData(target, nop.data(), nop.size()); | ||
|
||
// Jump | ||
WriteJump(target, func); | ||
} | ||
|
||
Trampoline::~Trampoline() | ||
{ | ||
if (codeData) | ||
VirtualFree(codeData, codeSize, MEM_DECOMMIT); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <windef.h> | ||
|
||
typedef void(*DetourFunction)(void); | ||
|
||
// TODO: Better documentation | ||
// TODO: Clearer member names | ||
// TODO: Code restoration | ||
|
||
class Trampoline | ||
{ | ||
private: | ||
void* target; | ||
DetourFunction detour; | ||
LPVOID codeData; | ||
size_t originalSize; | ||
size_t codeSize; | ||
|
||
public: | ||
/// <summary> | ||
/// Initializes a new <see cref="Trampoline" />, allowing you to replace functions and still call the original code. | ||
/// </summary> | ||
/// <param name="start">Start offset (address of function).</param> | ||
/// <param name="end">End offset.</param> | ||
/// <param name="func">Your detour function.</param> | ||
Trampoline(size_t start, size_t end, DetourFunction func); | ||
~Trampoline(); | ||
|
||
// Pointer to original code. | ||
LPVOID Target() const | ||
{ | ||
return codeData; | ||
} | ||
// Pointer to your detour. | ||
void* Detour() const | ||
{ | ||
return detour; | ||
} | ||
// Original data size. | ||
size_t OriginalSize() const | ||
{ | ||
return originalSize; | ||
} | ||
// Size of Target including appended jump to remaining original code. | ||
size_t CodeSize() const | ||
{ | ||
return codeSize; | ||
} | ||
}; |
Oops, something went wrong.