first commit

This commit is contained in:
itsmattkc 2019-04-27 23:23:41 +10:00
commit 2a554c8b87
4 changed files with 317 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.vs
*/obj/
*/bin/

25
Rebuilder.sln Normal file
View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.438
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rebuilder", "Rebuilder\Rebuilder.csproj", "{33C76194-8094-4682-A053-D0632C960DC1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{33C76194-8094-4682-A053-D0632C960DC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{33C76194-8094-4682-A053-D0632C960DC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33C76194-8094-4682-A053-D0632C960DC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33C76194-8094-4682-A053-D0632C960DC1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3BDD9BF2-C2CA-4E81-A32F-7F9EDAE61E65}
EndGlobalSection
EndGlobal

239
Rebuilder/Rebuilder.cs Normal file
View file

@ -0,0 +1,239 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing;
using System.Diagnostics;
using Microsoft.Win32;
namespace Rebuilder
{
class Rebuilder : Form
{
NumericUpDown turn_speed_control;
CheckBox redirect_saves;
CheckBox run_fullscreen;
Rebuilder() {
Text = "Lego Island Rebuilder";
MaximizeBox = false;
TableLayoutPanel grid = new TableLayoutPanel();
grid.Dock = DockStyle.Fill;
grid.ColumnCount = 2;
grid.RowCount = 4;
grid.AutoSize = true;
// Create automatic evenly spaced layout
float f = 100 / grid.ColumnCount;
for (int i=0;i<grid.ColumnCount;i++)
{
grid.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, f));
}
f = 100 / grid.RowCount;
for (int i = 0; i < grid.RowCount; i++)
{
grid.RowStyles.Add(new ColumnStyle(SizeType.Percent, f));
}
grid.SuspendLayout();
int row = 0;
Label title = new Label();
title.Anchor = AnchorStyles.Left | AnchorStyles.Right;
title.Text = "Lego Island Rebuilder";
title.Font = new Font(title.Font, FontStyle.Bold);
title.TextAlign = ContentAlignment.MiddleCenter;
grid.Controls.Add(title, 0, row);
grid.SetColumnSpan(title, 2);
row++;
LinkLabel subtitle = new LinkLabel();
subtitle.Anchor = AnchorStyles.Left | AnchorStyles.Right;
subtitle.Text = "by MattKC (itsmattkc.com)";
subtitle.TextAlign = ContentAlignment.MiddleCenter;
subtitle.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(AuthorLinkClick);
grid.Controls.Add(subtitle, 0, row);
grid.SetColumnSpan(subtitle, 2);
row++;
Label turn_speed_lbl = new Label();
turn_speed_lbl.Text = "Turn Speed:";
turn_speed_lbl.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
grid.Controls.Add(turn_speed_lbl, 0, row);
turn_speed_control = new NumericUpDown();
turn_speed_control.Minimum = 0;
turn_speed_control.Value = 20;
turn_speed_control.Anchor = AnchorStyles.Left | AnchorStyles.Right;
grid.Controls.Add(turn_speed_control, 1, row);
row++;
run_fullscreen = new CheckBox();
run_fullscreen.Checked = true;
run_fullscreen.Anchor = AnchorStyles.Left | AnchorStyles.Right;
run_fullscreen.Text = "Run in full screen";
grid.Controls.Add(run_fullscreen, 0, row);
grid.SetColumnSpan(run_fullscreen, 2);
row++;
redirect_saves = new CheckBox();
redirect_saves.Checked = true;
redirect_saves.Anchor = AnchorStyles.Left | AnchorStyles.Right;
redirect_saves.Text = "Redirect save files to %APPDATA%";
grid.Controls.Add(redirect_saves, 0, row);
grid.SetColumnSpan(redirect_saves, 2);
row++;
Button run_button = new Button();
run_button.Text = "Run";
run_button.Anchor = AnchorStyles.Left | AnchorStyles.Right;
run_button.Click += new System.EventHandler(this.Run);
grid.Controls.Add(run_button, 0, row);
grid.SetColumnSpan(run_button, 2);
ToolTip tip = new ToolTip();
tip.SetToolTip(turn_speed_control, "Set the turn speed multiplier.\n\n" +
"0 = No movement at all\n" +
"7 = Recommended for modern PCs\n" +
"20 = Lego Island's default\n\n" +
"NOTE: This also changes your movement speed, therefore reducing this will cripple your ability to win races.");
grid.ResumeLayout(true);
Controls.Add(grid);
AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink;
ResumeLayout(true);
CenterToScreen();
}
private void Write(FileStream fs, byte[] bytes, long pos = -1)
{
if (pos > -1)
{
fs.Position = pos;
}
fs.Write(bytes, 0, bytes.Length);
}
private void WriteInt32(FileStream fs, Int32 integer, long pos = -1)
{
byte[] int_bytes = BitConverter.GetBytes(integer);
Write(fs, int_bytes, pos);
}
private void WriteString(FileStream fs, string s, long pos = -1)
{
byte[] str_bytes = System.Text.Encoding.ASCII.GetBytes(s);
Write(fs, str_bytes, pos);
}
private void Patch(string dir)
{
// Patch LEGO1.DLL
using (FileStream fs = File.Open(dir + "/LEGO1.DLL", FileMode.Open, FileAccess.Write))
{
// Write turn speed hack (This undoubtedly opens up free bytes for more ASM, check it out at some point maybe)
Write(fs, new byte[]{ 0xEB, 0x1D }, 344889);
Write(fs, new byte[] { 0xEB, 0xCF }, 344918);
Write(fs, new byte[] { 0xC7, 0x44, 0x24, 0x14 }, 344920);
WriteInt32(fs, (Int32) turn_speed_control.Value);
Write(fs, new byte[] { 0xDA, 0x4C, 0x24, 0x14, 0xEB, 0xD7 });
if (redirect_saves.Checked)
{
// Write patch to write saves to "AppData" instead of "Program Files"
Write(fs, new byte[] { 0xE9, 0x61, 0x9B, 0x09, 0x00 }, 0x39300);
Write(fs, new byte[] { 0x53, 0xBB, 0x79, 0x3A, 0x0D, 0x10, 0x89, 0x5C, 0x24, 0x08, 0x56, 0x8B, 0x01, 0x57, 0xE9, 0x8C, 0x64, 0xF6, 0xFF }, 0xD2E66);
// New directory to write in (defaults to "%AppData%/LEGO Island")
string new_save_dir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\LEGO Island\\";
Directory.CreateDirectory(new_save_dir);
WriteString(fs, new_save_dir);
}
}
using (FileStream fs = File.Open(dir + "/ISLE.EXE", FileMode.Open, FileAccess.Write))
{
// This operation frees
if (run_fullscreen.Checked)
{
// Write all nops since full screen is enabled by default, frees up 13 bytes that were used to call the registry reading function
Write(fs, new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }, 0x1E03);
}
else
{
// Write 7 bytes to set the full screen value to 0, frees up 7 bytes of code that were used to call the registry reading function
Write(fs, new byte[] { 0xC7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90 }, 0x1E03);
}
}
}
private void Run(object sender, EventArgs e)
{
string temp_path = Path.GetTempPath() + "lirebuild";
Directory.CreateDirectory(temp_path);
string original_dir = "C:/Program Files (x86)/Lego Island";
try
{
File.Copy(original_dir + "/ISLE.EXE", temp_path + "/ISLE.EXE", true);
File.Copy(original_dir + "/LEGO1.DLL", temp_path + "/LEGO1.DLL", true);
}
catch
{
MessageBox.Show("Failed to patch files", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Patch(temp_path);
/*
// Set new EXE's compatibility mode to 256-colors
using (RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AppCompatFlags\\Layers", true))
{
key.CreateSubKey(temp_path + "\\ISLE.EXE");
key.SetValue(temp_path + "\\ISLE.EXE", "DWM8And16BitMitigation");
}
*/
ProcessStartInfo start_info = new ProcessStartInfo(temp_path + "/ISLE.EXE");
start_info.WorkingDirectory = original_dir;
Process p = Process.Start(start_info);
//Close();
}
private void AuthorLinkClick(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
((LinkLabel)sender).LinkVisited = true;
Process.Start("http://www.itsmattkc.com/");
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Rebuilder());
}
}
}

View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{33C76194-8094-4682-A053-D0632C960DC1}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>Rebuilder</RootNamespace>
<AssemblyName>Rebuilder</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Rebuilder.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>