Spellforce-Spell-framework
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"
15#include "../asi/sf_asi.h"
16#include <stdio.h>
17
19DebugLevel 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
34void 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
53void 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);
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 {
90 }
91 }
92 }
93 }
94
95 fclose(file);
96}
97
118BOOL 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 }
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
146
147 log_debug(DEBUG_INFO, "Loading Configs, Log Level is %s", debug_level_to_string(global_debug_level));
148
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}
void initialize_beta_hooks()
Definition sf_hooks.c:874
void log_error(const char *format,...)
void log_warning(const char *format,...)
Logs a warning at DEBUG_INFO, i.e. always shown.
void log_debug(DebugLevel level, const char *format,...)
const char * debug_level_to_string(DebugLevel level)
void log_info(const char *format,...)
@ SF_BETA
Definition sf_asi.h:12
bool __stdcall CheckSFVersion(SF_Version sf_version)
check version of the game that was hooked into
Definition sf_asi.cpp:54
bool Init(HMODULE lib_module)
required for everything to work... why?
Definition sf_asi.cpp:35
void initialize_framework()
Initializes the Spellforce Spell Framework (SFSF).
DebugLevel global_debug_level
Definition sfsf.cpp:18
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
Entry point for the DLL.
Definition sfsf.cpp:118
void load_debug_level_from_ini(const char *filename)
Definition sfsf.cpp:53
void create_default_ini_file(const char *filename)
Definition sfsf.cpp:34
DebugLevel parse_debug_level(const char *levelStr)
Definition sfsf.cpp:19
#define CONFIG_FILE
Definition sfsf.h:21