diff --git a/source/ArthursQuestBattlefortheKingdomFOVFix/ArthursQuestBattlefortheKingdomFOVFix.cpp b/source/ArthursQuestBattlefortheKingdomFOVFix/ArthursQuestBattlefortheKingdomFOVFix.cpp new file mode 100644 index 00000000..c8dc5171 --- /dev/null +++ b/source/ArthursQuestBattlefortheKingdomFOVFix/ArthursQuestBattlefortheKingdomFOVFix.cpp @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +#include +#include + +// Define M_PI if not already defined +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +// Function to convert degrees to radians +double degToRad(double degrees) +{ + return degrees * (M_PI / 180.0); +} + +// Function to convert radians to degrees +double radToDeg(double radians) +{ + return radians * (180.0 / M_PI); +} + +using namespace std; + +int main() +{ + double oldWidth = 4.0; + double oldHeight = 3.0; + double oldAspectRatio = oldWidth / oldHeight; + double oldHorizontalFOV = 90.0; // Known horizontal FOV for 4:3 aspect ratio + double newHorizontalFOV; + double newAspectRatio; + double newWidth, newHeight, horizontalFOV; + float horizontalFovInRadians; + + cout << "Arthur's Quest: Battle for the Kingdom FOV Fixer by AlphaYellow, 2024\n\n----------------\n\n"; + + do + { + cout << "\n- Enter the desired width: "; + cin >> newWidth; + + if (cin.fail()) + { + cin.clear(); // Clears error flags + cin.ignore(numeric_limits::max(), '\n'); // Ignores invalid input + newWidth = -1; // Ensures the loop continues + cout << "Invalid input. Please enter a numeric value." << endl; + } + else if (newWidth <= 0 || newWidth > 65535) + { + cout << "Please enter a positive number for width less than 65536." << endl; + } + } while (newWidth <= 0 || newWidth > 65535); + + do + { + cout << "\n- Enter the desired height: "; + cin >> newHeight; + + if (cin.fail()) + { + cin.clear(); // Clears error flags + cin.ignore(numeric_limits::max(), '\n'); // Ignores invalid input + newHeight = -1; // Ensures the loop continues + cout << "Invalid input. Please enter a numeric value." << endl; + } + else if (newHeight <= 0 || newHeight > 65535) + { + cout << "Please enter a positive number for height less than 65536." << endl; + } + } while (newHeight <= 0 || newHeight > 65535); + + newAspectRatio = newWidth / newHeight; + + // Calculates the new horizontal FOV + newHorizontalFOV = 2.0 * radToDeg(atan((newAspectRatio / oldAspectRatio) * tan(degToRad(oldHorizontalFOV / 2.0)))); + + fstream file("CShell.dll", ios::in | ios::out | ios::binary); + if (!file.is_open()) + { + cout << "Failed to open the file." << endl; + return 1; + } + + horizontalFovInRadians = static_cast(newHorizontalFOV * (M_PI / 180.0)); // Converts degrees to radians + + file.seekp(0x001AF741); + file.write(reinterpret_cast(&horizontalFovInRadians), sizeof(horizontalFovInRadians)); + + // Confirmation message + cout << "\nSuccessfully fixed the field view in the game.\n" + << endl; + + // Closes the file + file.close(); + + cout << "Press enter to exit the program..."; + cin.ignore(numeric_limits::max(), '\n'); // Clears the input buffer + cin.get(); + + return 0; +} \ No newline at end of file