Skip to content

Commit

Permalink
Split ACSE into Core & WinForms projects
Browse files Browse the repository at this point in the history
This will help code maintainability, and allow for cross platform support if another UI system is created.

Code refactoring will come at some point in the future.
  • Loading branch information
Cuyler36 committed Oct 31, 2018
1 parent d7a384c commit b8f8f86
Show file tree
Hide file tree
Showing 1,929 changed files with 7,705 additions and 1,505 deletions.
19 changes: 19 additions & 0 deletions ACSE.Core/ACSE.Core.csproj
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Costura.Fody" Version="3.1.6" />
<PackageReference Include="Fody" Version="3.2.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
</ItemGroup>

</Project>
23 changes: 16 additions & 7 deletions Classes/Acre/Acre.cs → ACSE.Core/Acres/Acre.cs
@@ -1,7 +1,11 @@
using System;
using System.IO;
using ACSE.Core.Debug;
using ACSE.Core.Items;
using ACSE.Core.Saves;
using ACSE.Core.Utilities;

namespace ACSE
namespace ACSE.Core.Acres
{
public class Acre
{
Expand All @@ -28,15 +32,17 @@ public class WorldAcre : Acre
{
public WorldItem[] AcreItems = new WorldItem[16 * 16];

public WorldAcre(ushort acreId, int position, ushort[] items = null, byte[] buriedItemData = null, SaveType saveType = SaveType.AnimalCrossing, uint[] nlItems = null, int townPosition = -1) : base(acreId, position)
public WorldAcre(ushort acreId, int position, ushort[] items = null, byte[] buriedItemData = null,
SaveType saveType = SaveType.AnimalCrossing, uint[] nlItems = null, int townPosition = -1) : base(acreId,
position)
{
if (items != null)
{
for (var i = 0; i < 256; i++)
{
AcreItems[i] = new WorldItem(items[i], i);
if (buriedItemData != null)
SetBuried(AcreItems[i], townPosition == -1 ? position : townPosition, buriedItemData, saveType); //Broken in original save editor lol.. needs a position - 1 to function properly
SetBuried(AcreItems[i], townPosition == -1 ? position : townPosition, buriedItemData, saveType);
}
}
else if (nlItems != null)
Expand All @@ -54,25 +60,28 @@ public WorldAcre(ushort acreId, int position, ushort[] items = null, byte[] buri
public WorldAcre(ushort acreId, int position, uint[] items = null, byte[] buriedItemData = null, SaveType saveType = SaveType.AnimalCrossing)
: this(acreId, position, null, null, saveType, items) { }

public WorldAcre(ushort acreId, int position, WorldItem[] items, byte[] buriedItemData = null, SaveType saveType = SaveType.AnimalCrossing, int townPosition = -1) : base(acreId, position)
public WorldAcre(ushort acreId, int position, WorldItem[] items, byte[] buriedItemData = null,
SaveType saveType = SaveType.AnimalCrossing, int townPosition = -1) : base(acreId, position)
{
AcreItems = items;
if (buriedItemData == null || townPosition <= -1) return;
for (var i = 0; i < 256; i++)
SetBuried(AcreItems[i], townPosition, buriedItemData, saveType);
}

//TODO: Change BuriedData from byte[] to ushort[] and use updated code
private static int GetBuriedDataLocation(WorldItem item, int acre, SaveType saveType)
{
if (item == null) return -1;
var worldPosition = 0;
switch (saveType)
{
//15 - item.Location.X because it's stored as a ushort in memory w/ reversed endianess
case SaveType.AnimalCrossing:
case SaveType.DoubutsuNoMoriEPlus:
case SaveType.AnimalForestEPlus:
case SaveType.CityFolk:
worldPosition = (acre * 256) + (15 - item.Location.X) + item.Location.Y * 16; //15 - item.Location.X because it's stored as a ushort in memory w/ reversed endianess
worldPosition = (acre * 256) + (15 - item.Location.X) + item.Location.Y * 16;
break;
case SaveType.WildWorld:
worldPosition = (acre * 256) + item.Index;
Expand Down Expand Up @@ -110,7 +119,7 @@ private static void SetBuried(WorldItem item, int acre, byte[] buriedItemData, S
/// <returns>bool ItemsWereLoaded</returns>
public bool LoadDefaultItems(Save saveFile)
{
var defaultAcreDataFolder = MainForm.AssemblyLocation + Path.DirectorySeparatorChar + "Resources" + Path.DirectorySeparatorChar + "Default Acre Items";
var defaultAcreDataFolder = Path.Combine(PathUtility.GetExeDirectory(), "Resources", "Default Acre Items");

switch (saveFile.SaveGeneration)
{
Expand Down Expand Up @@ -140,7 +149,7 @@ public bool LoadDefaultItems(Save saveFile)
}
catch
{
MainForm.DebugManager.WriteLine(
DebugUtility.DebugManagerInstance.WriteLine(
$"Unable to open default acre data for Acre Id 0x{BaseAcreId:X4}", DebugLevel.Error);
}

Expand Down
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using ACSE.Core.Players;
using ACSE.Core.Saves;

namespace ACSE
namespace ACSE.Core.BitFields.Catalog
{
public static class Catalog
{
Expand Down
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using ACSE.Core.Players;
using ACSE.Core.Saves;

namespace ACSE
namespace ACSE.Core.BitFields.Encyclopedia
{
public static class Encyclopedia
{
Expand Down Expand Up @@ -280,8 +282,6 @@ public static class Encyclopedia
case SaveType.WelcomeAmiibo:
return WelcomeAmiiboEncyclopediaBitMap;
default:
System.Windows.Forms.MessageBox.Show("Encylopedia data for this game has not been implemented yet!", "Unimplemented Notification",
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
return null;
}
}
Expand Down
5 changes: 4 additions & 1 deletion Classes/Museum.cs → ACSE.Core/BitFields/Museum/Museum.cs
@@ -1,4 +1,7 @@
namespace ACSE
using ACSE.Core.Players;
using ACSE.Core.Saves;

namespace ACSE.Core.BitFields.Museum
{
public static class Museum
{
Expand Down
@@ -1,6 +1,8 @@
using System.Collections.Generic;
using ACSE.Core.Players;
using ACSE.Core.Saves;

namespace ACSE
namespace ACSE.Core.BitFields.SongLibrary
{
public static class SongLibrary
{
Expand Down Expand Up @@ -110,8 +112,6 @@ public static class SongLibrary
case SaveType.WelcomeAmiibo:
return WelcomeAmiiboSongLibraryBitMap;
default:
System.Windows.Forms.MessageBox.Show("Songs for this game have not been implemented yet!", "Unimplemented Notification",
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
return null;
}
}
Expand Down
7 changes: 4 additions & 3 deletions Classes/Building.cs → ACSE.Core/Buildings/Building.cs
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using ACSE.Core.Saves;

namespace ACSE
namespace ACSE.Core.Buildings
{
/// <summary>
/// Building class for editing buildings in City Folk & New Leaf.
Expand Down Expand Up @@ -496,7 +497,7 @@ public static Building[] GetBuildings(Save save, bool islandBuildings = false)
if (islandBuildings == false)
for (var i = 0; i < 58; i++)
{
var dataOffset = save.SaveDataStartOffset + MainForm.CurrentSaveInfo.SaveOffsets.Buildings +
var dataOffset = save.SaveDataStartOffset + Save.SaveInstance.SaveInfo.SaveOffsets.Buildings +
i * 4;
buildings.Add(new Building(save.ReadByte(dataOffset), save.ReadByte(dataOffset + 2),
save.ReadByte(dataOffset + 3), save.SaveType));
Expand All @@ -506,7 +507,7 @@ public static Building[] GetBuildings(Save save, bool islandBuildings = false)
for (var i = 0; i < 2; i++)
{
var dataOffset = save.SaveDataStartOffset +
MainForm.CurrentSaveInfo.SaveOffsets.IslandBuildings + i * 4;
Save.SaveInstance.SaveInfo.SaveOffsets.IslandBuildings + i * 4;
buildings.Add(new Building(save.ReadByte(dataOffset), save.ReadByte(dataOffset + 2),
save.ReadByte(dataOffset + 3), save.SaveType));
}
Expand Down
16 changes: 11 additions & 5 deletions Classes/DebugManager.cs → ACSE.Core/Debug/DebugManager.cs
@@ -1,7 +1,8 @@
using System;
using System.IO;
using ACSE.Core.Saves;

namespace ACSE
namespace ACSE.Core.Debug
{
public enum DebugLevel
{
Expand All @@ -17,13 +18,18 @@ public class DebugManager
private FileStream _logFile;
private StreamWriter _logWriter;
private const int MaxLogSize = 5000000; // 5MB Max Size
public Save SaveFile;

public bool Enabled;
public DebugLevel Level;

public DebugManager()
public DebugManager(Save saveFile, DebugLevel level = DebugLevel.Info)
{
SaveFile = saveFile;
Level = level;
CheckAndDeleteLogFile();

if (Properties.Settings.Default.DebugLevel > 0)
if (level > 0)
{
InitializeDebugLogWriter();
Enabled = true;
Expand Down Expand Up @@ -86,7 +92,7 @@ private void CheckAndDeleteLogFile()

public void WriteLine(string contents, DebugLevel level = DebugLevel.Info)
{
if (_logWriter == null || level > Properties.Settings.Default.DebugLevel) return;
if (_logWriter == null || level > Level) return;
if (!CheckLogSizeOk())
{
CloseDebugLogWriter();
Expand All @@ -95,7 +101,7 @@ public void WriteLine(string contents, DebugLevel level = DebugLevel.Info)
}

_logWriter.WriteLine(
$"[{level}] - ({(MainForm.SaveFile != null ? MainForm.SaveFile.SaveType.ToString().Replace("_", " ") : "No Save")}) - {DateTime.Now} => {contents}");
$"[{level}] - ({(SaveFile != null ? SaveFile.SaveType.ToString().Replace("_", " ") : "No Save")}) - {DateTime.Now} => {contents}");
_logWriter.Flush();
}
}
Expand Down
5 changes: 4 additions & 1 deletion Classes/Emotion.cs → ACSE.Core/Emotions/Emotion.cs
@@ -1,4 +1,7 @@
namespace ACSE
using ACSE.Core.Players;
using ACSE.Core.Saves;

namespace ACSE.Core.Emotions
{
public static class Emotion
{
Expand Down
@@ -1,9 +1,10 @@
using System;
using ACSE.Core.Utilities;

namespace ACSE
namespace ACSE.Core.Encryption
{
/*
* Animal Crossing: New Leaf (and Welcome Amiibo) Interger Encryption Documentation
* Animal Crossing: New Leaf (and Welcome Amiibo) Integer Encryption Documentation
*
* Animal Crossing: New Leaf uses a combination of methods to obfuscate their integer values in the save file.
* The encryption consists of two integer values. The first integer is the encrypted integer. The second integer contains the checksum of the encryption and
Expand Down Expand Up @@ -52,7 +53,7 @@ public NewLeafInt32(uint intA, uint intB)

if (intChecksum != computedChecksum)
{
MainForm.DebugManager.WriteLine(
DebugUtility.DebugManagerInstance.WriteLine(
$"Encrypted Int had an invalid Checksum! Checksum: 0x{intChecksum:X2} | Calculated Checksum: 0x{computedChecksum:X2}");
Int1 = 0;
Int2 = 0;
Expand All @@ -71,7 +72,7 @@ public NewLeafInt32(uint intA, uint intB)
}
else
{
MainForm.DebugManager.WriteLine("Invalid Shift Count was detected!", DebugLevel.Info);
DebugUtility.DebugManagerInstance.WriteLine("Invalid Shift Count was detected!");
Value = (intA << rightShiftCount) - (adjustValue + 0x8F187432);
Valid = true; // Is this right?
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Enums.cs → ACSE.Core/Enums/Enums.cs
@@ -1,6 +1,6 @@
namespace ACSE
namespace ACSE.Core.Enums
{
// TODO: Move all enums to this file
// TODO: Split all enums into their own files.
public enum AnimalCrossingGrassType : byte
{
Triangle = 0,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions ACSE.Core/FodyWeavers.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;

namespace ACSE.Generators
namespace ACSE.Core.Generators
{
public class GCNGenerator : IGenerator
public sealed class GCNGenerator : IGenerator
{
private int _randomSeed = Environment.TickCount;

Expand Down
@@ -1,4 +1,6 @@
namespace ACSE.Generators
using ACSE.Core.Saves;

namespace ACSE.Core.Generators
{
public static class Generator
{
Expand Down
@@ -1,4 +1,4 @@
namespace ACSE.Generators
namespace ACSE.Core.Generators
{
public interface IGenerator
{
Expand Down
30 changes: 17 additions & 13 deletions Classes/House/House.cs → ACSE.Core/Housing/House.cs
@@ -1,7 +1,11 @@
using ACSE.Utilities;
using System.Reflection;

namespace ACSE
using System.Reflection;
using ACSE.Core.Encryption;
using ACSE.Core.Items;
using ACSE.Core.Players;
using ACSE.Core.Saves;
using ACSE.Core.Utilities;

namespace ACSE.Core.Housing
{
public class House
{
Expand All @@ -17,20 +21,20 @@ public House(int index, int offset, int roomCount = -1, int roomStart = -1)
Index = index;
Offset = offset;

var houseSize = HouseInfo.GetHouseSize(offset, MainForm.SaveFile.SaveType);
var houseSize = HouseInfo.GetHouseSize(offset, Save.SaveInstance.SaveType);
var basement = false;
//Console.WriteLine("House Index: " + Index);
//Console.WriteLine("House Offset: 0x" + Offset.ToString("X"));
//Console.WriteLine("House Size: " + HouseSize.ToString());
if (MainForm.SaveFile.SaveGeneration == SaveGeneration.N64 || MainForm.SaveFile.SaveGeneration == SaveGeneration.GCN)
if (Save.SaveInstance.SaveGeneration == SaveGeneration.N64 || Save.SaveInstance.SaveGeneration == SaveGeneration.GCN)
{
basement = HouseInfo.HasBasement(offset, MainForm.SaveFile.SaveType);
basement = HouseInfo.HasBasement(offset, Save.SaveInstance.SaveType);
//Console.WriteLine("Basement: " + Basement.ToString());
}

// Load House Data
var offsets = HouseInfo.GetHouseOffsets(MainForm.SaveFile.SaveType);
var saveData = MainForm.SaveFile;
var offsets = HouseInfo.GetHouseOffsets(Save.SaveInstance.SaveType);
var saveData = Save.SaveInstance;
var playerDataType = typeof(HouseData);
var playerSaveInfoType = typeof(HouseOffsets);
object boxedData = new HouseData();
Expand Down Expand Up @@ -156,7 +160,7 @@ public House(int index, int offset, int roomCount = -1, int roomStart = -1)

public virtual void Write()
{
var saveData = MainForm.SaveFile;
var saveData = Save.SaveInstance;
var offsets = HouseInfo.GetHouseOffsets(saveData.SaveType);

// Set House TownID & Name
Expand All @@ -165,15 +169,15 @@ public virtual void Write()
if (offsets.OwningPlayerName != -1 && offsets.TownId != -1)
{
Data.TownId =
saveData.ReadUInt16(saveData.SaveDataStartOffset + MainForm.CurrentSaveInfo.SaveOffsets.TownId,
saveData.ReadUInt16(saveData.SaveDataStartOffset + Save.SaveInstance.SaveInfo.SaveOffsets.TownId,
saveData.IsBigEndian); // Might not be UInt16 in all games
}

if (offsets.OwningPlayerName != -1 && offsets.TownName != -1)
{
Data.TownName = saveData.ReadString(
saveData.SaveDataStartOffset + MainForm.CurrentSaveInfo.SaveOffsets.TownName,
MainForm.CurrentSaveInfo.SaveOffsets.TownNameSize);
saveData.SaveDataStartOffset + Save.SaveInstance.SaveInfo.SaveOffsets.TownName,
Save.SaveInstance.SaveInfo.SaveOffsets.TownNameSize);
}

if (offsets.OwningPlayerName != -1)
Expand Down

0 comments on commit b8f8f86

Please sign in to comment.