Hello Matt!
Ok, I'll try to explain better what I did to translate the game:
First, install mplus-1m-regular.ttf font in your system. It is the font used in the phone messages and you'll need it to be able to calculate the sizes.
Then, download and install
https://seotoolsforexcel.com/
They are a collection of Excel tools. One of them is "PixelWidth" that calculate the width of a given string.
If you want to use this tools, you may need to purchase them (or search for a "pirate" version in internet).
Once installed, download this file
https://mega.nz/#!KVEVDaiL!7U2-GJ-OO0dj ... p5XbXa3GVA and open it in Excel. You'll have 2 columns: A->"ID" and B->"STRING". Add a new column C with the translated texts.
Open the Visual Basic window in Excel and paste this code in a module:
Function TextSize(str As String) As String
Dim splitedText() As String
splitedText = Split(str, " ")
Dim lines As Integer
lines = 1
Dim maxWidth As Double
maxWidth = 0
Dim acum As Double
If (Left$(str, 1) = " ") Then
acum = 43.5
Else
acum = 34
End If
Dim i As Integer
Dim tempWidth As Double
For i = 0 To UBound(splitedText)
tempWidth = GetWordWidth(splitedText(i), i <> UBound(splitedText))
If (acum + tempWidth < 347.5) Then
acum = acum + tempWidth
If acum > maxWidth Then
maxWidth = acum
End If
Else
acum = 34 + tempWidth
lines = lines + 1
End If
Next i
Dim height As Integer
height = lines * 24 + 28
TextSize = RoundUp(maxWidth) & ";" & height
End Function
Function GetWordWidth(word As String, addSpace As Boolean) As Double
Dim char As String
Dim i As Integer
Dim result As Double
result = 0
For i = 1 To Len(word)
char = Mid$(word, i, 1)
result = result + GetCharWidth(char)
Next i
If addSpace Then
result = result + 9.5
End If
GetWordWidth = result
End Function
Function GetCharWidth(char As String) As Double
Dim charWidth As Integer
If (char = " " Or char = "'") Then
charWidth = 9
ElseIf (Asc(char) = 160) Then
charWidth = 18
Else
charWidth = Application.Run("PixelWidth", char, "M+ 1m", 18) ' This is a function from SeoTools (
https://seotoolsforexcel.com/)
End If
If charWidth = 9 Then
GetCharWidth = 9.5
Else
GetCharWidth = 19.5
End If
End Function
It is a Excel function that calculates the box size needed for a given string.
Add the formula: "=TextSize($C2)" to the "D2" cell and propagate it down to cover all the strings.
So, at this moment, you have a Excel Sheet with 4 columns: ID, ORIGINAL TEXT, TRANSLATED TEXT, SIZE
Export columns "A" and "D" to a csv file using semicolons ( ; ) to separate fields. (I saved it as "F:\tmp\Traduccion JJ\boxsizes.csv". If you use other name or other path, you'll need to change it before compiling the second app)
Make a copy of the original resources_00001.-13 file. (I saved it as "F:\tmp\Traduccion JJ\original_resources_00001.-13". Same as before, if you save it to another path, you'll need to change it in the app)
Now you can compile and execute this app written in C#:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Gibbed.IO;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var dict = new Dictionary<int, SizeF>();
var lines = File.ReadAllLines(@"F:\tmp\Traduccion JJ\boxsizes.csv");
foreach (var line in lines)
{
var splt = line.Split(';');
var key = Convert.ToInt32(splt[0]);
var width = Convert.ToSingle(splt[1]);
var height = Convert.ToSingle(splt[2]);
var sz = new SizeF(width, height);
dict.Add(key, sz);
}
using (var input = new BinaryReader(new FileStream(@"F:\tmp\Traduccion JJ\original_resources_00001.-13", FileMode.Open)))
using (var output = new BinaryWriter(new FileStream(@"G:\Games\The Missing JJ Macfield and the Island of Memories\TheMISSING_Data\Unity_Assets_Files\resources\resources_00001.-13", FileMode.Open)))
{
input.Seek(0x150, SeekOrigin.Begin);
output.Seek(0x150, SeekOrigin.Begin);
var heightCount = input.ReadInt32();
for (var i = 0; i < heightCount; i++)
{
var nameLength = input.ReadInt32();
var name = input.ReadChars(nameLength + 1);
var msgEnum = input.ReadInt32();
input.ReadInt32();
input.ReadBytes(8);
output.Seek((int)input.BaseStream.Position, SeekOrigin.Begin);
if (dict.ContainsKey(msgEnum))
{
var sz = dict[msgEnum];
output.Write(sz.Width);
output.Write(sz.Height);
}
input.ReadBytes(24);
}
}
}
}
}
It will read the "boxsizes.csv" file and update the "resources_00001.-13" located at "G:\Games\The Missing JJ Macfield and the Island of Memories\TheMISSING_Data\Unity_Assets_Files\resources\". As I said before, you'll have to edit the app code if you use different file paths.
Once finished, you can repack the game files and try it.
The function that calculates the box size isn't perfect, and some messages are cut off in the game. In this case, edit the box size by hand in the excel, export again the csv, run the c# app and test again. You'll need a 100% completed game to check if all the phone messages are correct.
I hope I've explained myself better now.
Best regards!