Skip to content

Commit

Permalink
updatee
Browse files Browse the repository at this point in the history
  • Loading branch information
hinqiwame authored Oct 8, 2024
1 parent ffb46f0 commit fe4f7a0
Showing 1 changed file with 56 additions and 25 deletions.
81 changes: 56 additions & 25 deletions src/cof-patcher-core.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// NOTE: The patcher applies only base patches to ensure smooth and playable expirience for Cry of Fear on Linux.
// NOTE: The patcher applies only base patches to ensure smooth and playable experience for Cry of Fear on Linux.
// Use it on clean installation of Cry of Fear.
// You can get the idea of how you can modify the code to extend patcher's functionality by checking out the comments.

Expand All @@ -7,76 +7,107 @@
#include <string.h>
#include <sys/stat.h>

void movefile(const char* source, const char* destination) {
void movefile(const char* source, const char* destination)
{
FILE* src = fopen(source, "rb");
FILE* dest = fopen(destination, "wb");
if (src && dest) {
char buffer[4096];
size_t bytesRead;
while ((bytesRead = fread(buffer, 1, sizeof(buffer), src)) > 0) {
fwrite(buffer, 1, bytesRead, dest);
}
fclose(src);
fclose(dest);

if (!src || !dest) {
printf("[-] Error opening files: %s or %s\n", source, destination);
if (src) fclose(src);
if (dest) fclose(dest);
return;
}

char buffer[4096];
size_t bytesRead;

while ((bytesRead = fread(buffer, 1, sizeof(buffer), src)) > 0) {
fwrite(buffer, 1, bytesRead, dest);
}

fclose(src);
fclose(dest);
}

void patch(const char* path) {
void patch(const char* path)
{
printf("[*] Checking provided directory...\n");
struct stat dirStat;

if (stat(path, &dirStat) == 0) {
printf("[+] Directory check passed\n");
} else {
printf("[-] Provided directory does not exist, exiting...\n");
perror("[-] Provided directory does not exist, exiting...");
exit(1);
}

char fullPath[1024];

printf("[*] Moving files...\n");

printf("[*] Replacing cof.exe...\n");
movefile("patches/cof.exe", strcat(path, "/cof.exe"));
strcpy(fullPath, path);
strcat(fullPath, "/cof.exe");
movefile("patches/cof.exe", fullPath);
printf("[+] cof.exe replaced!\n");

printf("[~] Deleting opengl32.dll in the OG directory...\n");
remove(strcat(path, "/opengl32.dll"));
printf("[+] opengl32.dll removed!\n");
strcpy(fullPath, path);
strcat(fullPath, "/opengl32.dll");
if (remove(fullPath) == 0) {
printf("[+] opengl32.dll removed!\n");
} else {
printf("[-] Failed to delete opengl32.dll\n");
}

printf("[*] Moving opengp32.dll...\n");
movefile("patches/opengp32.dll", strcat(path, "/opengp32.dll"));
strcpy(fullPath, path);
strcat(fullPath, "/opengp32.dll");
movefile("patches/opengp32.dll", fullPath);
printf("[+] opengp32.dll moved!\n");

printf("[*] Replacing hw.dll...\n");
movefile("patches/hw.dll", strcat(path, "/hw.dll"));
strcpy(fullPath, path);
strcat(fullPath, "/hw.dll");
movefile("patches/hw.dll", fullPath);
printf("[+] hw.dll replaced!\n");

printf("[*] Replacing client.dll...\n");
movefile("patches/client.dll", strcat(path, "/cryoffear/cl_dlls/client.dll"));
strcpy(fullPath, path);
strcat(fullPath, "/cryoffear/cl_dlls/client.dll");
movefile("patches/client.dll", fullPath);
printf("[+] client.dll replaced!\n");

// At this point only base patches would have been applied.
// If you want to install any additional mods or whatever, place the files you need in "patches" directory and use it like shown below:

/*
printf("[*] Patching unlockables...\n");
movefile("patches/scriptsettings.dat", strcat(path, "/cryoffear/scriptsettings.dat"));
strcpy(fullPath, path);
strcat(fullPath, "/cryoffear/scriptsettings.dat");
movefile("patches/scriptsettings.dat", fullPath);
printf("[+] Unlockables patched!\n");
*/

// Remember to recompile the program if you modified it. You can use compiler script in this directory.
// Remember to recompile the program if you modified it. You can use compiler script in this directory.

printf("[*] Everything is done. Happy halloween! :)\n"); // :)
}

int main(int argc, char* argv[]) {
int main(int argc, char* argv[])
{
if (argc > 1 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0)) {
printf("Cry of Fear Linux patcher core v0.0.3\n\nDescription: Replaces game and engine libraries to patched ones. Fixes most of the Cry of Fear bugs for Linux.\n\nUsage: %s /path/to/cof\n\nOptional arguments:\n -h, --help\t\tShow this help message and exit.\n -v, --version\tDisplay the version of the build and exit.\n\nGithub: https://github.com/hinqiwame/cof-linux-patcher\n", argv[0]);
} else if (argc > 1 && (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0)) {
printf("0.0.3\n");
} else {
if (argc != 2) {
printf("You didn't provide enough arguments.\nSee %s --help.\n", argv[0]);
exit(EXIT_FAILURE);
}
const char* path = argv[1];
printf("You didn't provide enough arguments.\nSee %s --help.\n", argv[0]);
exit(EXIT_FAILURE);
}

const char* path = argv[1];
patch(path);
}

Expand Down

0 comments on commit fe4f7a0

Please sign in to comment.