This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
W Batt
committed
Sep 26, 2016
1 parent
f9ec683
commit d30a239
Showing
26 changed files
with
7,466 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerrariaUSaveEditor", "TerrariaUSaveEditor\TerrariaUSaveEditor.csproj", "{289EE2AD-A1C9-479A-9425-CE9F384374DC}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{289EE2AD-A1C9-479A-9425-CE9F384374DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{289EE2AD-A1C9-479A-9425-CE9F384374DC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{289EE2AD-A1C9-479A-9425-CE9F384374DC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{289EE2AD-A1C9-479A-9425-CE9F384374DC}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace TerrariaUSaveEditor.Helper | ||
{ | ||
public static class ArrayHelper | ||
{ | ||
public static byte[] RemoveRange(byte[] data, int index, int length) | ||
{ | ||
var buffer = data.ToList(); | ||
buffer.RemoveRange(index, length); | ||
|
||
return buffer.ToArray(); | ||
} | ||
|
||
public static byte[] AddRangeAtIndex(byte[] data, byte[] extraData, int index) | ||
{ | ||
var buffer = data.ToList(); | ||
buffer.InsertRange(index, extraData.ToList()); | ||
|
||
return buffer.ToArray(); | ||
} | ||
|
||
public static byte[] ColorToByteArray(Color color) | ||
{ | ||
byte[] colorArray = new byte[3]; | ||
colorArray[0] = color.R; | ||
colorArray[1] = color.G; | ||
colorArray[2] = color.B; | ||
|
||
return colorArray; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace TerrariaUSaveEditor.Helper | ||
{ | ||
public static class ItemHelper | ||
{ | ||
public static List<InventoryData> GetItems(byte[] data, SlotType slotType) | ||
{ | ||
List<InventoryData> items = new List<InventoryData>(); | ||
ushort slot = 0; | ||
|
||
for (int i = 0; i < data.Length; i+=5) | ||
{ | ||
var idArray = new byte[2]; | ||
Array.Copy(data, i, idArray, 0, 2); | ||
|
||
if (IsEmptySlot(idArray)) | ||
{ | ||
i -= 3; | ||
} | ||
|
||
int id = GetIDFromBytes(idArray); | ||
|
||
items.Add(new InventoryData() | ||
{ | ||
Slot = slot, | ||
Item = Items.GetItem(id), | ||
SlotType = slotType, | ||
Prefix = (ushort)data[i + 4], | ||
Amount = (ushort)data[i + 3] | ||
}); | ||
|
||
slot++; | ||
|
||
if (GotAllSlots(slotType, slot)) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
return items; | ||
} | ||
|
||
private static bool GotAllSlots(SlotType slotType, int currentSlot) | ||
{ | ||
switch (slotType) | ||
{ | ||
case SlotType.Bar: | ||
return currentSlot == 10 ? true : false; | ||
case SlotType.Inv: | ||
return currentSlot == 30 ? true : false; | ||
case SlotType.Ammo: | ||
return currentSlot == 4 ? true : false; | ||
case SlotType.Money: | ||
return currentSlot == 4 ? true : false; | ||
default: | ||
throw new ArgumentException("Invalid SlotType"); | ||
} | ||
} | ||
|
||
private static bool IsEmptySlot(byte[] idData) | ||
{ | ||
if (idData[0] == 0 && | ||
idData[1] == 0) | ||
{ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static int GetIDFromBytes(byte[] idData) | ||
{ | ||
if (idData[1] == 0) | ||
{ | ||
return BitConverter.ToInt16(idData, 0); | ||
} | ||
|
||
Array.Reverse(idData); | ||
return BitConverter.ToInt16(idData, 0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace TerrariaUSaveEditor.Helper | ||
{ | ||
public static class OffsetHelper | ||
{ | ||
// Name length change all offsets. | ||
public static int NameLength { get; set; } | ||
|
||
// Empty slots get written as "00 00". Used slots uses 5 bytes. "ID ID ?? AMOUNT PREFIX" | ||
public static int InventoryLength { get; set; } | ||
|
||
private static int OffsetDiff => Name + NameLength; | ||
|
||
// Character Offsets | ||
public static int NameLengthInformation => 0x02; | ||
public static int Name => 0x03; | ||
public static int Difficutly => OffsetDiff + 0x00; | ||
public static int Gender => OffsetDiff + 0x02; | ||
|
||
// Color Offsets | ||
public static int HairColor => OffsetDiff + 0x0B; | ||
public static int BodyColor => HairColor + 0x03; | ||
public static int EyeColor => BodyColor + 0x03; | ||
public static int ShirtColor => EyeColor + 0x03; | ||
public static int UnderShirtColor => ShirtColor + 0x03; | ||
public static int PantsColor => UnderShirtColor + 0x03; | ||
public static int ShoesColor => PantsColor + 0x03; | ||
|
||
// Equip Offsets | ||
/* | ||
* Equip get saved right after Colors. 1 Accessory take 3 Bytes "ID ID ?PREFIX?" | ||
* Again 2 Bytes as "00 00" if the slot is empty. | ||
* Based on this informations for accessory's, equipable items like armor should behave the same. | ||
* */ | ||
|
||
// Inventory Offsets | ||
public static int Inventory => OffsetDiff + 0x03D; | ||
|
||
public static int CalcOffsetDiffInventory(List<InventoryData> invData) | ||
{ | ||
int usedSlots = 0; | ||
int emptySlots = 0; | ||
foreach (var item in invData) | ||
{ | ||
if (item.Item.Id != 0) | ||
{ | ||
usedSlots++; | ||
} | ||
else | ||
{ | ||
emptySlots++; | ||
} | ||
} | ||
|
||
return (emptySlots * 2) + (usedSlots * 5); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
|
||
namespace TerrariaUSaveEditor | ||
{ | ||
public static class ValidationHelper | ||
{ | ||
public static bool IsNameValid(string name, out string error) | ||
{ | ||
error = "OK"; | ||
if (string.IsNullOrEmpty(name)) | ||
{ | ||
error = "Name can't be empty."; | ||
return false; | ||
} | ||
|
||
if (name.Length > 16) | ||
{ | ||
error = "Name is longer then 16 chars."; | ||
return false; | ||
} | ||
|
||
if (!Regex.Match(name, @"^[a-zA-Z 0-9\?\!\*]*$").Success) | ||
{ | ||
error = "Only a-z, A-Z, 0-9, ?, * and ! are allowed chars."; | ||
//error = $"Only a-z, A-Z, 0-9, ?, * and !{Environment.NewLine} are allowed chars."; | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public static bool IsNameValid(string name) | ||
{ | ||
string error = string.Empty; | ||
return IsNameValid(name, out error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace TerrariaUSaveEditor | ||
{ | ||
public enum SlotType | ||
{ | ||
Bar, | ||
Inv, | ||
Ammo, | ||
Money | ||
} | ||
|
||
public class InventoryData | ||
{ | ||
public ushort Slot { get; set; } | ||
|
||
public SlotType SlotType { get; set; } | ||
|
||
public ItemData Item { get; set; } | ||
|
||
public int Prefix { get; set; } | ||
|
||
public ushort Amount { get; set; } | ||
|
||
public InventoryData() | ||
{ | ||
} | ||
|
||
public InventoryData(ushort slot, SlotType slotType) | ||
{ | ||
this.Slot = slot; | ||
this.SlotType = slotType; | ||
this.Item = Items.GetItem(0); | ||
this.Prefix = 0; | ||
this.Amount = 0; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Drawing; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace TerrariaUSaveEditor | ||
{ | ||
public partial class ItemBox : Panel | ||
{ | ||
public ItemBox() | ||
{ | ||
this.InitializeComponent(); | ||
this.BorderStyle = BorderStyle.FixedSingle; | ||
this.BackColor = Color.FromArgb(0 ,178, 238); | ||
this.Size = new Size(45, 45); | ||
} | ||
|
||
public ItemBox(bool topBar) | ||
: this() | ||
{ | ||
if (topBar) | ||
{ | ||
this.BackColor = Color.FromArgb(0, 191, 255); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.