summaryrefslogtreecommitdiff
blob: b19ba8763e7958fef832ba1dadcad800f1e2b52c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
diff --git a/Makefile b/Makefile
index bc7297b..38afe9d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,8 @@
 # Makefile for et-sdl-sound
 
-# _GCC_PATH=/usr/x86_64-pc-linux-gnu/gcc-bin/3.4.6/
-
-LD = $(_GCC_PATH)g++
-CPP = $(_GCC_PATH)g++
-CC = $(_GCC_PATH)gcc
+LD = g++
+CPP = g++
+CC = gcc
 
 BUILD = build
 RELEASE = release
@@ -63,7 +61,6 @@ quake3-sdl-sound: $(LIB) $(SCRIPT_IN) embed-lib
 release: $(SCRIPTS)
 	mkdir -p $(RELEASE)/et-sdl-sound
 	cp *.hpp *.cpp *.in *.c README CHANGELOG $(SCRIPTS) $(LIB) $(RELEASE)/et-sdl-sound/
-	sed 's/^_GCC_PATH/\# _GCC_PATH/g' Makefile > $(RELEASE)/et-sdl-sound/Makefile
 	
 	cd $(RELEASE) && tar -czf et-sdl-sound.tar.gz et-sdl-sound
 	
diff --git a/hooks.cpp b/hooks.cpp
index 9da834b..cc52bc2 100644
--- a/hooks.cpp
+++ b/hooks.cpp
@@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 #include <sys/mman.h>
 #include <cstdlib>
 #include <limits.h>
+#include <unistd.h>
 
 #ifdef __SDL
 #include <SDL/SDL.h>
@@ -57,6 +58,11 @@ void initHooks()
 	const char *version = "UNKNOWN";
 	bool quake3 = false;
 	
+	// open logfile - using stdout leads to segfaults
+    std::ofstream logfile;
+    logfile.open ("/tmp/et-sdl-sound.log");
+    logfile << "---start---" << std::endl;
+	
 	switch (CRC32)
 	{
 	case 0xdc49bc09:
@@ -159,7 +165,8 @@ void initHooks()
 		dma = (dma_t *) 0x08aedc04;
 		break;
 	
-	case 0x6ab49f82:
+	case 0x6ab49f82: //Vanilla
+	case 0x91b6b864: //Arch Linux
 		version = "ET 2.60b";
 		
 		writeJump((void *) 0x08188250, (void *) SNDDMA_Init);
@@ -218,34 +225,34 @@ void initHooks()
 		break;
 	
 	default:
-		std::cout << "You are not running a recognized version of Enemy Territory or RTCW (CRC32 = " << (void *) CRC32  << ")" << std::endl;
+		logfile << "You are not running a recognized version of Enemy Territory or RTCW (CRC32 = " << (void *) CRC32  << ")" << std::endl;
 		return; // we don't need to exit( 1 )
 	}
 	
-	std::cout << "Found " << version << " (CRC32 = " << (void *) CRC32 << ")" << std::endl;
+	logfile << "Found " << version << " (CRC32 = " << (void *) CRC32 << ")" << std::endl;
 	
 	if (backend == OSS) {
-		std::cout << "Using default OSS backend." << std::endl;
+		logfile << "Using default OSS backend." << std::endl;
 		return;
 	}
 #ifdef __ALSA
 	else if (backend == ALSA) {
-		std::cout << "Using ALSA backend." << std::endl;
+		logfile << "Using ALSA backend." << std::endl;
 		etalsa = new EtALSA(dma);
 	}
 #endif
 #ifdef __SDL
 	else if (backend == SDL) {
-		std::cout << "Using SDL backend." << std::endl;
+		logfile << "Using SDL backend." << std::endl;
 		etsdl = new EtSDL(dma, (void *) sdl_audio_callback, quake3);
 	}
 #endif
 	else {
-		std::cout << "Requested backend is not available, using OSS." << std::endl;
+		logfile << "Requested backend is not available, using OSS." << std::endl;
 		return;
 	}
 	
-	std::cout << "et-sdl-sound-" << __ETSDL_VERSION << " (" << __DATE__ << " " << __TIME__ << ", " << __VERSION__ << ") loaded." << std::endl;
+	logfile << "et-sdl-sound-" << __ETSDL_VERSION << " (" << __DATE__ << " " << __TIME__ << ", " << __VERSION__ << ") loaded." << std::endl;
 }
 
 void writeAddr(void *addr, void *dest)
@@ -271,20 +278,14 @@ void unprotectPage(void *addr)
 	mprotect((void*) (((unsigned long) addr) & 0xfffff000), 4096, PROT_READ | PROT_WRITE | PROT_EXEC);
 }
 
-void printMem(void *addr, int size)
+void printMem(void *addr, int size) //May be broken
 {
-	std::cout << addr << ": ";
 	for (int i = 0; i < size; i++)
 		printf("%02x ", ((unsigned char*) addr)[i]);
-	std::cout << std::endl;
 }
 
 qboolean SNDDMA_Init(void)
 {
-#ifdef __DEBUG
-	std::cout << "SNDDMA_Init()" << std::endl;
-#endif
-
 #ifdef __ALSA
 	if (backend == ALSA)
 		return etalsa->init();
@@ -299,10 +300,6 @@ qboolean SNDDMA_Init(void)
 
 int SNDDMA_GetDMAPos(void)
 {
-#ifdef __DEBUG
-	std::cout << "SNDDMA_GetDMAPos()" << std::endl;
-#endif
-
 #ifdef __ALSA
 	if (backend == ALSA)
 		return etalsa->getDMAPos();
@@ -318,10 +315,6 @@ int SNDDMA_GetDMAPos(void)
 
 void SNDDMA_Shutdown(void)
 {
-#ifdef __DEBUG
-	std::cout << "SNDDMA_Shutdown()" << std::endl;
-#endif
-
 #ifdef __ALSA
 	if (backend == ALSA)
 		etalsa->shutdown();
@@ -335,10 +328,6 @@ void SNDDMA_Shutdown(void)
 
 void SNDDMA_BeginPainting(void)
 {
-#ifdef __DEBUG
-	std::cout << "SNDDMA_BeginPainting()" << std::endl;
-#endif
-
 #ifdef __ALSA
 	if (backend == ALSA)
 		etalsa->beginPainting();
@@ -352,10 +341,6 @@ void SNDDMA_BeginPainting(void)
 
 void SNDDMA_Submit(void)
 {
-#ifdef __DEBUG
-	std::cout << "SNDDMA_Submit()" << std::endl;
-#endif
-
 #ifdef __ALSA
 	if (backend == ALSA)
 		etalsa->submit();
@@ -379,7 +364,7 @@ unsigned int calculateProcCRC32()
 	ssize_t len;
 	
 	if ((len = readlink("/proc/self/exe", filename, sizeof(filename) - 1)) < 1) {
-		std::cout << "Can't find actual binary." << std::endl;
+		//logfile << "Can't find actual binary." << std::endl;
 		return 0x00000000;
 	}
 	filename[len] = '\0';
@@ -389,7 +374,7 @@ unsigned int calculateProcCRC32()
 	exe.open(filename);
 	
 	if (!exe.is_open() | !exe.good()) {
-		std::cout << "Can't open " << filename << std::endl;
+		//logfile << "Can't open " << filename << std::endl;
 		return 0x00000000;
 	}
 	
@@ -402,7 +387,7 @@ unsigned int calculateProcCRC32()
 	exe.read((char*) file, fsize);
 	exe.close();
 	
-	std::cout << "Read " << filename << " (" << fsize << " bytes)" << std::endl;
+	//logfile << "Read " << filename << " (" << fsize << " bytes)" << std::endl;
 	
 	// generate crc_table
 	unsigned int crc_table[256];
diff --git a/launcher-script.in b/launcher-script.in
index 3692e3e..0b1e676 100644
--- a/launcher-script.in
+++ b/launcher-script.in
@@ -87,7 +87,7 @@ testlibsdl () {
 	fi
 	
 	if [ "$LIBSDL" = "" -a -f "$1" ]; then
-		if [ "`file -b "$1" | grep "ELF 32-bit LSB shared object"`" != "" ]; then
+		if [ "`file -b "$1" | grep "ELF 32-bit LSB"`" != "" ]; then
 			info "32-bit libSDL.so is installed to $1"
 			LIBSDL="$1"
 		fi
@@ -103,6 +103,7 @@ fi
 [ "$GAME_PATH" = "" ] && testgamepath "/usr/local/games/$GAME_DIR"
 [ "$GAME_PATH" = "" ] && testgamepath "/opt/$GAME_DIR"
 [ "$GAME_PATH" = "" ] && testgamepath "/usr/games/$GAME_DIR"
+[ "$GAME_PATH" = "" ] && testgamepath "/usr/share/"
 [ "$GAME_PATH" = "" ] && testgamepath "~/$GAME_DIR"
 if [ "$GAME_PATH" = "" ]; then
 	LOCATE_GAME=`locate "$GAME_BIN" 2> /dev/null`
@@ -113,7 +114,7 @@ if [ "$GAME_PATH" = "" ]; then
 	done
 fi
 if [ "$GAME_PATH" = "" -a "$USE_FIND" = "yes" ]; then
-	FIND_GAME=`find /opt/ /usr/ -type f -name "$GAME_BIN"`
+	FIND_GAME=`find /opt/ /usr/ . -type f -name "$GAME_BIN"`
 	for i in $FIND_GAME; do
 		i=`dirname "$i"`
 		testgamepath $i
@@ -154,9 +155,21 @@ fi
 echo -ne "$ET_SDL_SOUND_LIB" > "$TMP_DIR/et-sdl-sound.so" || eend "can't write $TMP_DIR/et-sdl-sound.so"
 info "library is written to $TMP_DIR/et-sdl-sound.so"
 
+if [ ! -f $GAME_PATH/$GAME_BIN ]; then
+	error "Game binary not found"
+	info "Path was: $GAME_PATH/$GAME_BIN"
+	exit 1
+fi
+
 info "launching the game..."
 cd "$GAME_PATH"
 
+info "Path: $GAME_PATH"
+info "CWD: `pwd`"
+info "SDL: $LIBSDL"
+info "Driver: $SDL_AUDIODRIVER"
+info "Call: LD_PRELOAD="${LD_PRELOAD}:${TMP_DIR}/et-sdl-sound.so" ./$GAME_BIN $*"
+
 export ETSDL_SDL_LIB="$LIBSDL"
 export SDL_AUDIODRIVER="$SDL_AUDIODRIVER"
 LD_PRELOAD="${LD_PRELOAD}:${TMP_DIR}/et-sdl-sound.so" ./$GAME_BIN $*