Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Add support for re-calling internal value functions
Browse files Browse the repository at this point in the history
  • Loading branch information
BC46 committed Jan 28, 2024
1 parent 58e32e1 commit b8852b5
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 10 deletions.
26 changes: 26 additions & 0 deletions include/internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

// Generic function definitions
typedef void (__fastcall GenericClassFunc)(PVOID ecx, PVOID edx);
typedef void (GenericFunc)();

struct FuncInfo
{
LPCSTR moduleName;
DWORD fileOffset;
};

struct ClassFuncInfo
{
LPCSTR moduleName;
DWORD fileOffset;
DWORD thisPtr;
};

// This function is used to effectively re-set some internal values in the Freelancer binaries
// We use this because otherwise some patches may have no effect due to memory being read before FLPatch is loaded
// Thanks to this function, the patched values will actually be used
void SetInternalValues();
4 changes: 3 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ $(BIN_DIR):
if not exist $(BIN_DIR) mkdir $(BIN_DIR)

# Dependencies
$(SRC_DIR)\main.cpp: $(INCLUDE_DIR)\utils.h $(INCLUDE_DIR)\Common.h
$(SRC_DIR)\main.cpp: $(INCLUDE_DIR)\utils.h $(INCLUDE_DIR)\Common.h $(INCLUDE_DIR)\internal.h
$(SRC_DIR)\internal.cpp: $(INCLUDE_DIR)\internal.h
$(SRC_DIR)\utils.cpp: $(INCLUDE_DIR)\utils.h

clean:
del $(BIN_DIR)\*.dll $(OBJ_DIR)\*.obj $(OBJ_DIR)\*.RES $(OBJ_DIR)\*.lib
8 changes: 4 additions & 4 deletions rc/main.rc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <winver.h>

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,2,0,0
PRODUCTVERSION 0,2,0,0
FILEVERSION 0,3,0,0
PRODUCTVERSION 0,3,0,0
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
{
Expand All @@ -12,12 +12,12 @@ FILETYPE VFT_DLL
{
VALUE "CompanyName", "BC46"
VALUE "FileDescription", "FLPatch"
VALUE "FileVersion", "0.2"
VALUE "FileVersion", "0.3"
VALUE "InternalName", "FLPatch"
VALUE "LegalCopyright", "Copyright 2023 BC46"
VALUE "OriginalFilename", "FLPatch.dll"
VALUE "ProductName", "Freelancer"
VALUE "ProductVersion", "0, 2, 0, 0"
VALUE "ProductVersion", "0, 3, 0, 0"
}
}

Expand Down
45 changes: 45 additions & 0 deletions src/internal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "internal.h"

LPCSTR flModule = "freelancer.exe";
LPCSTR commonModule = "common.dll";

void SetInternalValues()
{
int i;

const FuncInfo funcs[] =
{
{ flModule, 0x10100 }, // Poly flipping distance #1
{ flModule, 0x10120 }, // Poly flipping distance #2
{ flModule, 0x11B2D0 }, // Poly flipping distance #3
{ commonModule, 0x62E40 }, // Maximum docking initiation distance
};

const ClassFuncInfo classFuncs[] =
{
{ flModule, 0x1628E0, 0x67ADC4 } // Filter out incompatible builds on server by default
};

for (i = 0; i < sizeof(funcs) / sizeof(FuncInfo); ++i)
{
DWORD module = (DWORD) GetModuleHandleA(funcs[i].moduleName);

if (!module)
continue;

GenericFunc* func = (GenericFunc*) (module + funcs[i].fileOffset);
(func)();
}

for (i = 0; i < sizeof(classFuncs) / sizeof(ClassFuncInfo); ++i)
{
DWORD module = (DWORD) GetModuleHandleA(classFuncs[i].moduleName);

if (!module)
continue;

GenericClassFunc* classFunc = (GenericClassFunc*) (module + classFuncs[i].fileOffset);

(classFunc)((PVOID) classFuncs[i].thisPtr, NULL);
}
}
7 changes: 2 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <windows.h>

#include "utils.h"
#include "internal.h"
#include "Common.h"

#define LOAD_LIBRARY_RPC_OFFSET 0xF20E
Expand Down Expand Up @@ -115,14 +116,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
UNREFERENCED_PARAMETER(hinstDLL);
UNREFERENCED_PARAMETER(lpReserved);

// TODO:
// Call set value functions common.dll and Freelancer.exe
// fl 1C8910: Single (float32) 20000 -> 40000. Increases the poly flipping distance, which allows jumpholes and other effects to be seen from further away.
// common 13F48C: Single (float32) 10000 -> 50000. Increases the maximum docking initiation distance.

if (fdwReason == DLL_PROCESS_ATTACH)
{
LoadPatches();
SetInternalValues();

// If the client is running, we want to set a hook so we can apply patches to server.dll as well since this one gets loaded later
if (!IsMPServer())
Expand Down

0 comments on commit b8852b5

Please sign in to comment.