Spellforce-Spell-framework
Toggle main menu visibility
Loading...
Searching...
No Matches
sfsf.cpp
Go to the documentation of this file.
1
6
10
11
#include <windows.h>
12
#include "
core/sf_hooks.h
"
13
#include "
core/sf_wrappers.h
"
14
#include "
registry/sf_registry.h
"
15
#include "
../asi/sf_asi.h
"
16
#include <stdio.h>
17
18
DebugLevel
global_debug_level
=
DEBUG_INFO
;
19
DebugLevel
parse_debug_level
(
const
char
*levelStr)
20
{
21
if
(strcasecmp(levelStr,
"INFO"
) == 0)
22
return
DEBUG_INFO
;
23
if
(strcasecmp(levelStr,
"LOW"
) == 0)
24
return
DEBUG_LOW
;
25
if
(strcasecmp(levelStr,
"MED"
) == 0)
26
return
DEBUG_MED
;
27
if
(strcasecmp(levelStr,
"HIGH"
) == 0)
28
return
DEBUG_HIGH
;
29
if
(strcasecmp(levelStr,
"ALL"
) == 0)
30
return
DEBUG_ALL
;
31
return
DEBUG_INFO
;
32
}
33
34
void
create_default_ini_file
(
const
char
*filename)
35
{
36
FILE *file = fopen(filename,
"w"
);
37
if
(!file)
38
{
39
log_error
(
"Failed to create default config file: %s"
, filename);
40
return
;
41
}
42
43
fprintf(file,
44
"; Default SFSF configuration\n"
45
"[Logging]\n"
46
"; (INFO, LOW, MED, HIGH, ALL)\n"
47
"DebugLevel=INFO\n"
);
48
fclose(file);
49
50
log_info
(
"Created default config file: %s"
, filename);
51
}
52
53
void
load_debug_level_from_ini
(
const
char
*filename)
54
{
55
FILE *file = fopen(filename,
"r"
);
56
if
(!file)
57
{
58
log_warning
(
"Config file not found: %s"
, filename);
59
create_default_ini_file
(filename);
60
return
;
61
}
62
63
char
line[256];
64
int
inLoggingSection = 0;
65
66
while
(fgets(line,
sizeof
(line), file))
67
{
68
char
*start = line;
69
while
(isspace((
unsigned
char
)*start))
70
++start;
71
72
if
(*start ==
';'
|| *start ==
'#'
|| *start ==
'\n'
|| *start ==
'\0'
)
73
continue
;
74
75
if
(*start ==
'['
)
76
{
77
if
(strncasecmp(start,
"[Logging]"
, 9) == 0)
78
inLoggingSection = 1;
79
else
80
inLoggingSection = 0;
81
}
82
else
if
(inLoggingSection)
83
{
84
char
key[128], value[128];
85
if
(sscanf(start,
" %127[^=]= %127s"
, key, value) == 2)
86
{
87
if
(strcasecmp(key,
"DebugLevel"
) == 0)
88
{
89
global_debug_level
=
parse_debug_level
(value);
90
}
91
}
92
}
93
}
94
95
fclose(file);
96
}
97
118
BOOL APIENTRY
DllMain
(HMODULE hModule, DWORD ul_reason_for_call,
119
LPVOID lpReserved)
120
{
121
switch
(ul_reason_for_call)
122
{
123
case
DLL_PROCESS_ATTACH:
124
{
125
OutputDebugStringA(
"[SFSF] |======================| Attach SFSF |======================|"
);
126
if
(!
ASI::Init
(hModule))
127
{
128
OutputDebugStringA(
"[SFSF] |======================| Bad Init |======================|"
);
129
OutputDebugStringA(
"[SFSF] Something is bad with either SFSF integrity or Spellforce Version"
);
130
return
FALSE;
131
}
132
if
(!
ASI::CheckSFVersion
(
ASI::SF_BETA
))
133
{
134
OutputDebugStringA(
"[SFSF] |======================| Bad Version |======================|"
);
135
OutputDebugStringA(
"[SFSF] Are you on public_test branch? Spellforce should be version 1.61.11213"
);
136
return
FALSE;
137
}
138
else
139
{
140
FILE *file = fopen(
"sfsf.log"
,
"w"
);
141
fclose(file);
142
143
log_info
(
"Spellforce Version Accepted; Starting SFSF"
);
144
145
load_debug_level_from_ini
(
CONFIG_FILE
);
146
147
log_debug
(
DEBUG_INFO
,
"Loading Configs, Log Level is %s"
,
debug_level_to_string
(
global_debug_level
));
148
149
initialize_framework
();
150
initialize_beta_hooks
();
151
OutputDebugStringA(
"[SFSF] |======================| Injection Complete |======================|"
);
152
break
;
153
}
154
break
;
155
}
156
case
DLL_PROCESS_DETACH:
157
OutputDebugStringA(
"[SFSF] Framework Detached"
);
158
break
;
159
}
160
return
TRUE;
161
}
initialize_beta_hooks
void initialize_beta_hooks()
Definition
sf_hooks.c:874
log_error
void log_error(const char *format,...)
Definition
sf_wrappers.c:153
log_warning
void log_warning(const char *format,...)
Logs a warning at DEBUG_INFO, i.e. always shown.
Definition
sf_wrappers.c:124
log_debug
void log_debug(DebugLevel level, const char *format,...)
Definition
sf_wrappers.c:182
debug_level_to_string
const char * debug_level_to_string(DebugLevel level)
Definition
sf_wrappers.c:169
log_info
void log_info(const char *format,...)
Definition
sf_wrappers.c:140
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::Init
bool Init(HMODULE lib_module)
required for everything to work... why?
Definition
sf_asi.cpp:35
sf_asi.h
DebugLevel
DebugLevel
Definition
sf_general_structures.h:36
DEBUG_HIGH
@ DEBUG_HIGH
Definition
sf_general_structures.h:40
DEBUG_INFO
@ DEBUG_INFO
Definition
sf_general_structures.h:37
DEBUG_MED
@ DEBUG_MED
Definition
sf_general_structures.h:39
DEBUG_LOW
@ DEBUG_LOW
Definition
sf_general_structures.h:38
DEBUG_ALL
@ DEBUG_ALL
Definition
sf_general_structures.h:41
sf_hooks.h
initialize_framework
void initialize_framework()
Initializes the Spellforce Spell Framework (SFSF).
Definition
sf_registry.cpp:113
sf_registry.h
sf_wrappers.h
global_debug_level
DebugLevel global_debug_level
Definition
sfsf.cpp:18
DllMain
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
Entry point for the DLL.
Definition
sfsf.cpp:118
load_debug_level_from_ini
void load_debug_level_from_ini(const char *filename)
Definition
sfsf.cpp:53
create_default_ini_file
void create_default_ini_file(const char *filename)
Definition
sfsf.cpp:34
parse_debug_level
DebugLevel parse_debug_level(const char *levelStr)
Definition
sfsf.cpp:19
CONFIG_FILE
#define CONFIG_FILE
Definition
sfsf.h:21
src
internal
sfsf.cpp
Generated by
1.17.0