Skip to content

Commit

Permalink
new file: source/fixes/BarbieAsTheIslandPrincessFOVFix.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
alphayellow1 committed Sep 28, 2024
1 parent 783ddb4 commit 02d2c5f
Showing 1 changed file with 177 additions and 0 deletions.
177 changes: 177 additions & 0 deletions source/fixes/BarbieAsTheIslandPrincessFOVFix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <conio.h> // For getch() function [get character]
#include <cstdint> // For uint32_t variable type
#include <limits>
#include <string>
#include <algorithm>

using namespace std;

// Constants
const streampos kAspectRatioOffset1 = 0x00250C94;
const streampos kAspectRatioOffset2 = 0x00250C98;

// Variables
uint32_t newWidth, newHeight;
string input, descriptor;
fstream file;
int choice1, choice2, tempChoice;
bool fileNotFound, validKeyPressed;
float newAspectRatio, newAspectRatioValue;
char ch;

// Function to handle user input in choices
void HandleChoiceInput(int &choice)
{
tempChoice = -1; // Temporary variable to store the input
validKeyPressed = false; // Flag to track if a valid key was pressed

while (true)
{
ch = _getch(); // Waits for user to press a key

// Checks if the key is '1' or '2'
if ((ch == '1' || ch == '2') && !validKeyPressed)
{
tempChoice = ch - '0'; // Converts char to int and stores the input temporarily
cout << ch; // Echoes the valid input
validKeyPressed = true; // Sets the flag as a valid key has been pressed
}
else if (ch == '\b' || ch == 127) // Handles backspace or delete keys
{
if (tempChoice != -1) // Checks if there is something to delete
{
tempChoice = -1; // Resets the temporary choice
cout << "\b \b"; // Erases the last character from the console
validKeyPressed = false; // Resets the flag as the input has been deleted
}
}
// If 'Enter' is pressed and a valid key has been pressed prior
else if (ch == '\r' && validKeyPressed)
{
choice = tempChoice; // Assigns the temporary input to the choice variable
cout << endl; // Moves to a new line
break; // Exits the loop since we have a confirmed input
}
}
}

// Function to handle user input in resolution
void HandleResolutionInput(uint32_t &newCustomResolutionValue)
{
do
{
cin >> newCustomResolutionValue;

cin.clear(); // Clears error flags
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // Ignores invalid input

if (cin.fail())
{
cin.clear(); // Clears error flags
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // Ignores invalid input
cout << "Invalid input. Please enter a numeric value." << endl;
}
else if (newCustomResolutionValue <= 0 || newCustomResolutionValue >= 65535)
{
cout << "Please enter a valid number." << endl;
}
} while (newCustomResolutionValue <= 0 || newCustomResolutionValue > 65535);
}

// Function to open the file
void OpenFile(fstream &file, const string &filename)
{
fileNotFound = false;

file.open(filename, ios::in | ios::out | ios::binary);

// If the file is not open, sets fileNotFound to true
if (!file.is_open())
{
fileNotFound = true;
}

// Loops until the file is found and opened
while (fileNotFound)
{
// Tries to open the file again
file.open(filename, ios::in | ios::out | ios::binary);

if (!file.is_open())
{
cout << "\nFailed to open " << filename << ", check if the executable has special permissions allowed that prevent the fixer from opening it (e.g: read-only mode), it's not present in the same directory as the fixer, or if the executable is currently running. Press Enter when all the mentioned problems are solved." << endl;
do
{
ch = _getch(); // Waits for user to press a key
} while (ch != '\r'); // Keeps waiting if the key is not Enter ('\r' is the Enter key in ASCII)
}
else
{
cout << "\n" << filename << " opened successfully!" << endl;
fileNotFound = false; // Sets fileNotFound to false as the file is found and opened
}
}
}

float NewAspectRatioCalculation(uint32_t &newWidthValue, uint32_t &newHeightValue)
{
newAspectRatioValue = static_cast<float>(newWidthValue) / static_cast<float>(newHeightValue);
return newAspectRatioValue;
}

int main()
{
cout << "Barbie as the Island Princess (2007) FOV Fixer v1.0 by AlphaYellow, 2024\n\n----------------\n";

do
{
OpenFile(file, "BarbieIP.exe");

cout << "\n- Enter the desired width: ";
HandleResolutionInput(newWidth);

cout << "\n- Enter the desired height: ";
HandleResolutionInput(newHeight);

newAspectRatio = NewAspectRatioCalculation(newWidth, newHeight);

file.seekp(kAspectRatioOffset1);
file.write(reinterpret_cast<const char *>(&newAspectRatio), sizeof(newAspectRatio));

file.seekp(kAspectRatioOffset2);
file.write(reinterpret_cast<const char *>(&newAspectRatio), sizeof(newAspectRatio));

// Checks if any errors occurred during the file operations
if (file.good())
{
// Confirmation message
cout << "\nSuccessfully fixed the field of view." << endl;
}
else
{
cout << "\nError(s) occurred during the file operations." << endl;
}

// Closes the file
file.close();

cout << "\n- Do you want to exit the program (1) or try another value (2)?: ";
HandleChoiceInput(choice2);

if (choice2 == 1)
{
cout << "\nPress Enter to exit the program...";
do
{
ch = _getch(); // Waits for user to press a key
} while (ch != '\r'); // Keeps waiting if the key is not Enter ('\r' is the Enter key in ASCII)
return 0;
}

cout << "\n-----------------------------------------\n";
} while (choice2 != 1); // Checks the flag in the loop condition
}

0 comments on commit 02d2c5f

Please sign in to comment.