Add customizable default names

This commit is contained in:
Lorenzo Carletti 2022-01-01 04:49:56 +01:00
parent 737fb02e64
commit 0e7ed4945e
6 changed files with 205 additions and 1 deletions

View File

@ -5,5 +5,7 @@ $pwd = $pwd.Path
if ($LASTEXITCODE -ne 0) { exit -1 }
& dotnet build tools/RenderCastRoll -o "$([IO.Path]::Combine($pwd, "bin/RenderCastRoll"))"
if ($LASTEXITCODE -ne 0) { exit -1 }
& dotnet build tools/SetDefaultNames -o "$([IO.Path]::Combine($pwd, "bin/SetDefaultNames"))"
if ($LASTEXITCODE -ne 0) { exit -1 }
& dotnet build tools/RenderStaffCredits -o "$([IO.Path]::Combine($pwd, "bin/RenderStaffCredits"))"
if ($LASTEXITCODE -ne 0) { exit -1 }

View File

@ -11,6 +11,7 @@ $src_dir = "src"
$data_dir = "src/data"
$give_new_dir = "src/m12-give-strings"
$cast_roll_file = "working/cast_roll.json"
$default_names_file = "working/default_names.json"
$staff_credits_file = "working/staff_text.md"
$compiled_asm_file = "src/m2-compiled.asm"
$includes_asm_file = "m12-includes.asm" # implicitly rooted in working_dir
@ -47,6 +48,7 @@ $input_c_test_files =
$base_c_address = 0x83755B8;
$scripttool_cmd = "bin/ScriptTool/ScriptTool.dll"
$rendercastroll_cmd = "bin/RenderCastRoll/RenderCastRoll.dll"
$setdefaultnames_cmd = "bin/SetDefaultNames/SetDefaultNames.dll"
$renderstaffcredits_cmd = "bin/RenderStaffCredits/RenderStaffCredits.dll"
$gcc_cmd = "arm-none-eabi-gcc"
$ld_cmd = "arm-none-eabi-ld"
@ -82,6 +84,10 @@ $rendercastroll_args =
$cast_roll_file,
$data_dir
$setdefaultnames_args =
$default_names_file,
$data_dir
$renderstaffcredits_args =
$staff_credits_file,
$data_dir
@ -402,6 +408,10 @@ if ($LASTEXITCODE -ne 0) { exit -1 }
"Copying give strings to src folder..."
Copy-Item -Path $give_dir -Destination $give_new_dir -Recurse
"Preparing default names..."
& dotnet $setdefaultnames_cmd $setdefaultnames_args
if ($LASTEXITCODE -ne 0) { exit -1 }
"Pre-rendering cast roll..."
& dotnet $rendercastroll_cmd $rendercastroll_args
if ($LASTEXITCODE -ne 0) { exit -1 }

View File

@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScriptToolGui", "ScriptTool
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenderCastRoll", "RenderCastRoll\RenderCastRoll.csproj", "{DD1C607C-5A74-4921-81A4-6BF530A191D7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RenderStaffCredits", "RenderStaffCredits\RenderStaffCredits.csproj", "{D4885175-8BD3-4B91-B905-6BA845DBDC2F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RenderStaffCredits", "RenderStaffCredits\RenderStaffCredits.csproj", "{D4885175-8BD3-4B91-B905-6BA845DBDC2F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SetDefaultNames", "SetDefaultNames\SetDefaultNames.csproj", "{0218AFDB-9AF2-4A24-A082-2578DC8E9BE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,6 +35,10 @@ Global
{D4885175-8BD3-4B91-B905-6BA845DBDC2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4885175-8BD3-4B91-B905-6BA845DBDC2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4885175-8BD3-4B91-B905-6BA845DBDC2F}.Release|Any CPU.Build.0 = Release|Any CPU
{0218AFDB-9AF2-4A24-A082-2578DC8E9BE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0218AFDB-9AF2-4A24-A082-2578DC8E9BE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0218AFDB-9AF2-4A24-A082-2578DC8E9BE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0218AFDB-9AF2-4A24-A082-2578DC8E9BE3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Newtonsoft.Json;
namespace SetDefaultNames
{
public class NamesEntry
{
public string entry { get; set; }
public string[] defaultNames { get; set; }
}
public class NamesEntryRoot
{
public List<NamesEntry> NamesEntries { get; set; }
}
class Program
{
static readonly int[] MaxSizes = { 5, 5, 5, 5, 6, 6, 6 };
static readonly int entry_size = 0x4C;
static readonly int entry_numbers = 7;
static readonly int encode_ascii = 48;
static void Main(string[] args)
{
if (args.Length != 2)
return;
//Initialization
string namesJson = File.ReadAllText(args[0]);
string dataFolder = args[1] + Path.DirectorySeparatorChar;
byte[] namesBin = File.ReadAllBytes(dataFolder + "m2-default-names.bin");
List<NamesEntry> entries = JsonConvert.DeserializeObject<NamesEntryRoot>(namesJson).NamesEntries;
for (int i = 0; i < MaxSizes.Length; i++)
{
for (int j = 0; j < entries[i].defaultNames.Length; j++)
{
byte[] convertedString = getTextBytes(entries[i].defaultNames[j]);
int size = Math.Min(convertedString.Length, MaxSizes[i]);
int pos = (i * entry_numbers * entry_size) + (j * entry_size);
insertInt(namesBin, pos, size);
for (int k = 0; k < 8; k++)
{
byte value = (k < size) ? convertedString[k] : (byte)0;
namesBin[pos + 4 + k] = value;
}
}
}
File.WriteAllBytes(dataFolder + "m2-default-names.bin", namesBin);
}
static void insertInt(byte[] bin, int pos, int val)
{
bin[pos] = (byte)((val) & 0xFF);
bin[pos + 1] = (byte)((val >> 8) & 0xFF);
bin[pos + 2] = (byte)((val >> 16) & 0xFF);
bin[pos + 3] = (byte)((val >> 24) & 0xFF);
}
static byte[] getTextBytes(String str)
{
//Reads a string and converts it to bytes
List<byte> tokens = new List<byte>();
for (int i = 0; str.Length > 0; i++)
{
string token = str[0].ToString();
str = str.Substring(1);
if (token == "[")
while (str.Length > 0 && !token.EndsWith("]"))
{
token += str[0].ToString();
str = str.Substring(1);
}
tokens.Add((byte)(Encoding.ASCII.GetBytes(token)[0] + encode_ascii));
}
return tokens.ToArray();
}
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,88 @@
{
"NamesEntries": [
{
"entry": "Ness",
"defaultNames": [
"Ness",
"Alec",
"Roger",
"Will",
"Brian",
"Tyler",
"Lane"
]
},
{
"entry": "Paula",
"defaultNames": [
"Paula",
"Nancy",
"Skye",
"Paige",
"Marie",
"Holly",
"Jane"
]
},
{
"entry": "Jeff",
"defaultNames": [
"Jeff",
"Dan",
"Henry",
"Isaac",
"Ralph",
"Sean",
"Rob"
]
},
{
"entry": "Poo",
"defaultNames": [
"Poo",
"Kato",
"Kai",
"Omar",
"Ramin",
"Aziz",
"Lado"
]
},
{
"entry": "Dog",
"defaultNames": [
"King",
"Peach",
"Sparky",
"Rex",
"Baby",
"Rover",
"Misty"
]
},
{
"entry": "Favourite Food",
"defaultNames": [
"Steak",
"Pie",
"Pasta",
"Cake",
"Eggs",
"Bread",
"Salmon"
]
},
{
"entry": "Favourite Thing",
"defaultNames": [
"Rockin",
"Hammer",
"Love",
"Gifts",
"Slime",
"Gaming",
"Boxing"
]
}
]
}