Spellforce-Spell-framework
Toggle main menu visibility
Loading...
Searching...
No Matches
sf_asi.cpp
Go to the documentation of this file.
1
#include "
sf_asi.h
"
2
3
namespace
ASI
4
{
6
bool
BeginRewrite
(
MemoryRegion
&mem_region)
7
{
8
return
VirtualProtect((LPVOID)mem_region.
memory_offset
,
9
(SIZE_T)mem_region.
memory_length
, 0x40,
// 0x40 - enable everything?
10
&mem_region.
old_reg_perm
);
11
}
12
14
bool
EndRewrite
(
MemoryRegion
&mem_region)
15
{
16
DWORD tmp_old_region_permission;
17
bool
b = VirtualProtect((LPVOID)mem_region.
memory_offset
,
18
(SIZE_T)mem_region.
memory_length
,
19
mem_region.
old_reg_perm
,
20
&tmp_old_region_permission) != 0;
21
if
(b)
22
FlushInstructionCache((HANDLE)0xFFFFFFFF, 0, 0);
23
return
b;
24
}
25
26
unsigned
int
GAME_BASE
;
27
int
WINDOW_OFFSET
;
28
unsigned
int
APPMAIN_OFFSET
;
29
void
SetGameBase
()
30
{
31
GAME_BASE
= (
unsigned
int)GetModuleHandleA(
"spellforce.exe"
);
32
}
33
35
bool
Init
(HMODULE lib_module)
36
{
37
if
(!DisableThreadLibraryCalls(lib_module))
38
return
false
;
39
ASI::SetGameBase
();
40
if
(
CheckSFVersion
(
SF_154
))
41
{
42
WINDOW_OFFSET
= 0x97CB5C;
43
APPMAIN_OFFSET
= 0x9644D0;
44
}
45
if
(
CheckSFVersion
(
SF_BETA
))
46
{
47
WINDOW_OFFSET
= 0x93A25C;
48
APPMAIN_OFFSET
= 0x9229A8;
// FIXME
49
}
50
return
true
;
51
}
52
54
bool
__stdcall
CheckSFVersion
(
SF_Version
sf_version)
55
{
56
switch
(sf_version)
57
{
58
case
SF_154
:
59
if
(*(
int
*)
ASI::AddrOf
(0xEFF8) == 75000)
// 1.54.75000
60
return
true
;
61
break
;
62
case
SF_161
:
63
if
(*(
int
*)
ASI::AddrOf
(0x1E6EE6) == 10180)
// 1.61.10180
64
return
true
;
65
break
;
66
case
SF_BETA
:
67
if
(*(
int
*)
ASI::AddrOf
(0x177e63) == 11213)
// 1.61.11213
68
return
true
;
69
default
:
70
return
false
;
71
}
72
return
false
;
73
}
74
}
ASI
Definition
sf_asi.cpp:4
ASI::AddrOf
int AddrOf(int offset)
returns "real" virtual address of given memory offset
Definition
sf_asi.h:135
ASI::SF_Version
SF_Version
Definition
sf_asi.h:9
ASI::SF_161
@ SF_161
Definition
sf_asi.h:11
ASI::SF_154
@ SF_154
Definition
sf_asi.h:10
ASI::SF_BETA
@ SF_BETA
Definition
sf_asi.h:12
ASI::CheckSFVersion
bool __stdcall CheckSFVersion(SF_Version sf_version)
check version of the game that was hooked into
Definition
sf_asi.cpp:54
ASI::BeginRewrite
bool BeginRewrite(MemoryRegion &mem_region)
allows rewriting code in a given memory region by overwriting permissions for that memory region
Definition
sf_asi.cpp:6
ASI::APPMAIN_OFFSET
unsigned int APPMAIN_OFFSET
Definition
sf_asi.cpp:28
ASI::WINDOW_OFFSET
int WINDOW_OFFSET
Definition
sf_asi.cpp:27
ASI::EndRewrite
bool EndRewrite(MemoryRegion &mem_region)
ends rewriting by restoring old permissions in a given memory region
Definition
sf_asi.cpp:14
ASI::GAME_BASE
unsigned int GAME_BASE
Definition
sf_asi.cpp:26
ASI::Init
bool Init(HMODULE lib_module)
required for everything to work... why?
Definition
sf_asi.cpp:35
ASI::SetGameBase
void SetGameBase()
Definition
sf_asi.cpp:29
sf_asi.h
ASI::MemoryRegion
MemoryRegion is used for rewriting code in a given memory block.
Definition
sf_asi.h:17
ASI::MemoryRegion::memory_offset
int memory_offset
Definition
sf_asi.h:18
ASI::MemoryRegion::old_reg_perm
DWORD old_reg_perm
Definition
sf_asi.h:20
ASI::MemoryRegion::memory_length
int memory_length
Definition
sf_asi.h:19
src
asi
sf_asi.cpp
Generated by
1.17.0