changeset 9:07f0e2f43204

*: add the restrict keyword when necessary also fixed some typos in the README
author Paper
date Fri, 16 Dec 2022 21:55:37 -0500
parents 00399cc5f7ce
children 42ac054c0231
files README.md src/config.c src/include/utils.h src/timer.c src/utils.c
diffstat 5 files changed, 15 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/README.md	Fri Dec 16 20:46:33 2022 -0500
+++ b/README.md	Fri Dec 16 21:55:37 2022 -0500
@@ -3,7 +3,7 @@
 This plugin is largely based off of clandrew's [wdrp](https://github.com/clandrew/wdrp). You can look at the screenshots in that repository, it looks pretty much identical.
 
 ### Installing
-You'll want to put gen_DiscordGameSDK.dll into Plugins directory, and discord_game_sdk into the Winamp directory.
+You'll want to put gen_DiscordGameSDK.dll into the `Plugins` directory, and discord_game_sdk.dll into the `Winamp` directory.
 
 ### Configuration
 The config file is located at `%AppData%\Roaming\Winamp\Plugins\wgsdk\config.txt`. It's pretty straightforward how to edit it.
--- a/src/config.c	Fri Dec 16 20:46:33 2022 -0500
+++ b/src/config.c	Fri Dec 16 21:55:37 2022 -0500
@@ -30,7 +30,7 @@
 extern void update_rich_presence_details(void);
 extern struct config config;
 
-int cfg_load(struct config* config) {
+int cfg_load(struct config* restrict config) {
 	char line[MAX_LINE_LENGTH] = {0},
 	     *path = dirtools_concat_paths(getenv("APPDATA"), "Winamp\\Plugins\\wgsdk\\config.txt");
 	FILE* config_fp = fopen(path, "r");
--- a/src/include/utils.h	Fri Dec 16 20:46:33 2022 -0500
+++ b/src/include/utils.h	Fri Dec 16 21:55:37 2022 -0500
@@ -1,7 +1,7 @@
 #ifndef __utils_h
 #define __utils_h
 
-long long get_system_time_in_milliseconds(void);
-unsigned int crc32b(unsigned char *message);
+uint64_t get_system_time_in_milliseconds(void);
+uint32_t crc32b(unsigned char *message);
 
 #endif
\ No newline at end of file
--- a/src/timer.c	Fri Dec 16 20:46:33 2022 -0500
+++ b/src/timer.c	Fri Dec 16 21:55:37 2022 -0500
@@ -5,29 +5,28 @@
 #include <windows.h>
 #include "timer.h"
 
-void timer_init(struct timer* timer, HWND winampClientWindow, TIMERPROC timer_proc) {
+void timer_init(struct timer* restrict timer, HWND winampClientWindow, TIMERPROC timer_proc) {
 	timer->winampClientWindow = winampClientWindow;
 	timer->timer_proc = timer_proc;
 	timer->initialized = 1;
 }
 
-void timer_set(struct timer* timer, HWND winampClientWindow) {
+void timer_set(struct timer* restrict timer, HWND winampClientWindow) {
 	assert(timer->initialized);
-	
+
 	if (timer->is_timer_alive)
 		return;
-	
+
 	timer->is_timer_alive = 1;
 	SetTimer(winampClientWindow, 1, timer->interval, timer->timer_proc);
 }
 
-void timer_stop(struct timer* timer, HWND winampClientWindow) {
+void timer_stop(struct timer* restrict timer, HWND winampClientWindow) {
 	assert(timer->initialized);
-	
+
 	if (!timer->is_timer_alive)
 		return;
-	
-	
+
 	timer->is_timer_alive = 0;
 	KillTimer(winampClientWindow, 1);
 }
\ No newline at end of file
--- a/src/utils.c	Fri Dec 16 20:46:33 2022 -0500
+++ b/src/utils.c	Fri Dec 16 21:55:37 2022 -0500
@@ -16,20 +16,18 @@
 	return ((ul - 116444736000000000ULL)/10000000);
 }
 
-unsigned int crc32b(unsigned char *message) {
-	int i, j;
-	unsigned int byte, crc, mask;
+uint32_t crc32b(unsigned char* restrict message) {
+	int32_t i, j;
+	uint32_t byte, crc, mask;
 
-	i = 0;
 	crc = 0xFFFFFFFF;
-	while (message[i] != 0) {
+	for (i = 0; message[i] != 0; i++) {
 		byte = message[i];            // Get next byte.
 		crc = crc ^ byte;
 		for (j = 7; j >= 0; j--) {    // Do eight times.
 			mask = -(crc & 1);
 			crc = (crc >> 1) ^ (0xEDB88320 & mask);
 		}
-		i = i + 1;
 	}
 	return ~crc;
 }