Skip to content

Commit

Permalink
copy from patcher repo
Browse files Browse the repository at this point in the history
  • Loading branch information
kyx0r committed Jan 6, 2019
1 parent 2d69254 commit de1517d
Show file tree
Hide file tree
Showing 46 changed files with 2,575 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.exe
/lib
/build
Env.ld
*.o
nop
140 changes: 140 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell sh -c 'uname -s 2>/dev/null || echo not')
endif

ifeq ($(detected_OS),Windows)
obj_type = i386pe
mkdir = mkdir $(subst /,\,$(1)) > nop 2>&1 || (exit 0)
rm = $(wordlist 2,65535,$(foreach FILE,$(subst /,\,$(1)),& del $(FILE) > nop 2>&1)) || (exit 0)
rmdir = rmdir $(subst /,\,$(1)) > nop 2>&1 || (exit 0)
echo = echo $(1)
else
obj_type = elf_i386
mkdir = mkdir -p $(1)
rm = rm $(1) > /dev/null 2>&1 || true
rmdir = rmdir $(1) > /dev/null 2>&1 || true
echo = echo "$(1)"
endif

ifeq ($(detected_OS),Windows)
WINAPI = -lmingw32 -lkernel32 -lm -ldxguid -ldxerr8 -luser32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lgdi32 -lcomdlg32 -lwinspool
WINAPI+= -lcomctl32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lshlwapi -lversion -lwinpthread -ldbghelp -lpthread
endif

OBJS = ./*cpp
HEADS = ./patcher/binPatcher.hpp
PREP = -include $(HEADS)
CC = g++

ASTYLE = aStyle

#LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS = -L ./lib

INCLUDE_PATHS = -I ./boost_lib -I .

align_size = 0x100
align_data = 0x1000
align_rdata = 0x1000
align_bss = 0x1000
align_idata = 0x1000

#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = FaPatcher.exe

#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
# -Wl,-subsystem,windows gets rid of the console window
COMPILER_FLAGS = -static -w -DOBJ_NAME='"$(OBJ_NAME)"' -O3 -s

#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -static-libgcc -static-libstdc++

LOCAL_LIBS = -lpatcher -lfilesystem -lsystem -lpebliss -lasmjit

#-oformat -Ttext=0x006B8FB9
#echo align_size = $(align_size)';' > Env.ld

align:
echo align_size = $(align_size)';' > Env.ld

peLib:
$(MAKE) all -C ./pe_lib

boostLib:
$(MAKE) all -C ./boost_lib/filesystem
$(MAKE) all -C ./boost_lib/system

patcherLib:
$(MAKE) all OBJ_NAME=$(OBJ_NAME) -C ./patcher

asmjitLib:
$(MAKE) all -C ./asmjit_lib

cleanall:
$(MAKE) clean -C ./boost_lib/filesystem
$(MAKE) clean -C ./boost_lib/system
$(MAKE) clean -C ./pe_lib
$(MAKE) clean -C ./asmjit_lib
$(MAKE) clean -C ./patcher
rm -Rf ./build

cleanbuild:
rm -Rf ./build

directories:
$(call mkdir, /build)
$(call mkdir, /preprocessor)

ext_sector:
$(MAKE) all_individual -C ./sections
$(MAKE) link -C ./sections

_hooks:
$(MAKE) all OBJ_NAME=$(OBJ_NAME_) OBJS=$(OBJS) -C ./hooks

_fast_hooks:
$(MAKE) fast_compile -C ./hooks

ext_gpp_link:
$(call echo, align_data = $(align_data)';' > Env.ld)
$(call echo, align_rdata = $(align_rdata)';' >> Env.ld)
$(call echo, align_bss = $(align_bss)';' >> Env.ld)
$(call echo, align_idata = $(align_idata)';' >> Env.ld)
echo align_data = $(align_data)';' > Env.ld
echo align_rdata = $(align_rdata)';' >> Env.ld
echo align_bss = $(align_bss)';' >> Env.ld
echo align_idata = $(align_idata)';' >> Env.ld
ld -T ./linker/sectionLinker.ld -static -m $(obj_type) $(PRIME_NAME) -o $(TMP_NAME)

hook_gpp_link:
$(call echo, align_size = $(align_size)';' > Env.ld)
echo align_size = $(align_size)';' > Env.ld
ld -T ./linker/hookLinker.ld -static -m $(obj_type) $(PRIME_NAME) -o $(TMP_NAME)

rip_out_binary:
objcopy --strip-all -O binary -R .eh_fram $(TMP_NAME) $(PRIME_NAME)

pre_comp_h:
$(CC) -w $(INCLUDE_PATHS) $(HEADS)

#This is the target that compiles our executable
all : peLib boostLib asmjitLib patcherLib
$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(LOCAL_LIBS) -o $(OBJ_NAME)
@echo ./FaPatcher built successfully.

allwin : peLib boostLib asmjitLib patcherLib
$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(LOCAL_LIBS) $(WINAPI) -o $(OBJ_NAME)
@echo ./FaPatcher built successfully.

format:
$(ASTYLE) --style=allman --indent=tab --recursive ./*.cpp, *.h, *.hpp

clean_f:
find . -type f -name '*.orig' -delete

clean_g:
find . -type f -name '*.gch' -delete

9 changes: 9 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
# FA Binary Patches Repository

This are some binary patches for Supreme Commander Forged Alliance.

To apply them build or get the pacther itself from here

https://github.com/FAETHER/FA_Patcher

This are just the patch files for this game. I decided to separate them from patcher source code.

52 changes: 52 additions & 0 deletions hooks/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell sh -c 'uname -s 2>/dev/null || echo not')
endif

SRCS=$(wildcard *.cpp)

FASTOBJS=$(SRCS:.cpp=.o)

PROGS = $(patsubst %.cpp,../build/%.o,$(SRCS))

#CC specifies which compiler we're using
CC = g++
#INCLUDE_PATHS specifies the additional include paths we'll need
#INCLUDE_PATHS = -I ./SDL2-2.0.8/i686-w64-mingw32/include/

#LIBRARY_PATHS specifies the additional library paths we'll need
#LIBRARY_PATHS = -L ./lib

LINKER_FLAGS = -I. -m32 -O0 -ffreestanding -fpermissive -fno-exceptions -fno-asynchronous-unwind-tables -c -w -Wextra -masm=intel -ffunction-sections -fdata-sections -Wl,--gc-sections

#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
# -Wl,-subsystem,windows gets rid of the console window
ifeq ($(detected_OS),Windows)
COMPILER_FLAGS = -fleading-underscore
endif

#LINKER_FLAGS specifies the libraries we're linking against
#-ffunction-sections -fdata-sections

#-ffreestanding = freestanding enviroment

#-nostartfiles similar to -c but has linker enabled

ASSEMBLER_FLAGS = -c -ffreestanding -fpermissive -fno-exceptions -fno-asynchronous-unwind-tables

#BOOST = -lboost_filesystem-mgw63-mt-d-x32-1_67 -lboost_thread-mgw63-mt-d-x32-1_67 -lboost_regex-mgw63-mt-d-x32-1_67 -lboost_system-mgw63-mt-d-x32-1_67

fast_compile: $(PROGS)
../build/%.o: %.cpp
$(CC) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $@ $<

all :
$(CC) $(OBJS) $(HEADS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(BOOST) -o $(OBJ_NAME)

genAssembly:
$(CC) $(OBJS) $(HEADS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(BOOST) -S $(OBJ_NAME)

assemble:
$(CC) ./*s $(HEADS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(ASSEMBLER_FLAGS) $(BOOST) -o $(OBJ_NAME)
9 changes: 9 additions & 0 deletions hooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This folder contains the hooks that overwrite at specific offset.

Files with .cpp are compiled by g++. Files with .jh are just data interpreted,

originally created by asmjit assembler.

Files with any other extensions are considered to be not used by default, and its up to the

user to decide if they are wanted.
16 changes: 16 additions & 0 deletions hooks/_IssueMove.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//HOOK OnMotionTurnEventChange ROffset = 0x002F2670

#include <stdlib.h>
#include "../preprocessor/define.h"
#include "../preprocessor/macro.h"

__asm__
(
".equ by_pass_address,"QU(dec_IssueMove)"-0x006F2670 \n"
);

__asm__ volatile
(
"call . + by_pass_address \n"
".align 128, 0x0 \n"
);
17 changes: 17 additions & 0 deletions hooks/hook_OnMotionTurnEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//HOOK OnMotionTurnEventChange ROffset = 0x2B8FB9

//org 0x006B8FB9
#include <stdlib.h>

//int by_pass_address asm("address") = 0x006B8FE0;

__asm__
(
".equ by_pass_address,0x006B8FE0-0x006B8FB9 \n"
);

__asm__ __volatile__
(
"jmp . + by_pass_address \n"
".align 128, 0x0 \n"
);
20 changes: 20 additions & 0 deletions hooks/hook_OnMotionTurnEvent2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//HOOK OnMotionTurnEventChange2 ROffset = 0x2B953F

//org 0x006B953F

#include <stdlib.h>

__asm__
(
".equ by_pass_address,0x006B9567-0x006B953F \n"
);

__asm__ __volatile__
(
"jmp . + by_pass_address \n"
".align 128, 0x0 \n"
);




24 changes: 24 additions & 0 deletions hooks/hook_OnMotionTurnEvent3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//HOOK OnMotionTurnEventChange2 ROffset = 0x2BFF2C

//org 0x006BFF2C

#include <stdlib.h>

__asm__
(
".equ by_pass_address,0x006BFF55-0x006BFF2C \n"
);

__asm__ __volatile__
(
"jmp . + by_pass_address \n"
".align 128, 0x0 \n"
);








15 changes: 15 additions & 0 deletions hooks/hook_Walls.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//HOOK WallSelection ROffset = 0x00465EC2
#include <stdlib.h>

__asm__ volatile
(
"nop \n"
"nop \n"
"nop \n"
"nop \n"
"nop \n"
"nop \n"
".align 128, 0x0 \n"
);


22 changes: 22 additions & 0 deletions hooks/hook_aiinitattack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//HOOK _aiinitattack compare with a null. ROffset = 0x80B4C2

#include <stdlib.h>

//address on the left is the current instruction position.
//on the right, address is the final position.
__asm__
(
".equ end_func_goto_thread_validation,0x00C0B4C5-0x005F3B99 \n"
".equ by_pass_address,0x00C0B4D1-0x005F39FD \n"
);

__asm__ __volatile__
(
"cmp ecx,0 \n"
"je . - end_func_goto_thread_validation \n"
"mov edx,dword ptr [ecx] \n"
"lea eax,dword ptr [ebp+0x60] \n"
"push eax \n"
"jmp . - by_pass_address \n"
".align 128, 0x0 \n"
);
16 changes: 16 additions & 0 deletions hooks/hook_aiinitattack_jmp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//HOOK _aiinitattack prevents a crash when a target is in range but null is encountered. ROffset = 0x1F39F7

//org 0x005F39F7
#include <stdlib.h>

__asm__
(
".equ by_pass_address,0x00C0B4C2-0x005F39F7 \n"
);

__asm__ __volatile__
(
"jmp . + by_pass_address \n"
"nop \n"
".align 128, 0x0 \n"
);
10 changes: 10 additions & 0 deletions hooks/jitH_AILuaFunc.jh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--base=C0B4F0
--offs=80B4F0
--arch=x86
cmp ecx, 0 ; 83F900
je 7126220 ; 0F84D307ACFF
lea edx, dword [esp+40] ; 8D542428
mov dword [esp+80], eax ; 89442450
jmp 7126094 ; E94807ACFF
BYTES:83F9000F84D307ACFF8D54242889442450E94807ACFF
5 changes: 5 additions & 0 deletions hooks/jitH_AILuaFuncJmp.jh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--base=6CBC46
--offs=2CBC46
--arch=x86
jmp 12629232 ; E9A5F85300
BYTES:E9A5F85300
6 changes: 6 additions & 0 deletions hooks/jitH_OnmotionTurnEvent.jh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--baseVA=6B8FB9
--offs=2B8FB9
--arch=x86

short jmp 7049184 ; EB25
BYTES:EB25
6 changes: 6 additions & 0 deletions hooks/jitH_OnmotionTurnEvent2.jh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--baseVA=6B953F
--offs=2B953F
--arch=x86

short jmp 7050599 ; EB26
BYTES:EB26
6 changes: 6 additions & 0 deletions hooks/jitH_OnmotionTurnEvent3.jh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--baseVA=6BFF2C
--offs=2BFF2C
--arch=x86

short jmp 7077717 ; EB27
BYTES:EB27
Loading

0 comments on commit de1517d

Please sign in to comment.