Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions SoG_SGreader/DataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
switch (quickSlotType)
{
case 1:
playerObject.Quickslots.Add((SogItem)readBinary.ReadInt32());
playerObject.Quickslots.Add(readBinary.ReadInt32());
break;
case 2:
playerObject.Quickslots.Add((SogSkill)readBinary.ReadUInt16());
playerObject.Quickslots.Add(readBinary.ReadUInt16());
break;
default:
playerObject.Quickslots.Add(0);
Expand Down Expand Up @@ -82,7 +82,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.Inventory.Add(new Item
{
ItemID = (SogItem)readBinary.ReadInt32(),
ItemID = readBinary.ReadInt32(),
ItemCount = readBinary.ReadInt32(),
ItemPos = readBinary.ReadUInt32()
});
Expand Down Expand Up @@ -292,7 +292,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.ItemsSeen.Add(new ItemSeen
{
ItemID = (SogItem) readBinary.ReadInt32()
ItemID = readBinary.ReadInt32()
});
}

Expand All @@ -305,7 +305,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.ItemsCrafted.Add(new ItemCrafted
{
ItemID = (SogItem) readBinary.ReadInt32()
ItemID = readBinary.ReadInt32()
});
}

Expand All @@ -318,7 +318,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.FishCaught.Add(new FishCaught
{
FishID = (SogItem) readBinary.ReadInt32()
FishID = readBinary.ReadInt32()
});
}

Expand Down Expand Up @@ -349,7 +349,7 @@ public static Player ReadFromFile(string fileName, ITextBoxWrapper txtConsole)
{
playerObject.Potions.Add(new Potion
{
PotionID = (SogItem)readBinary.ReadInt32()
PotionID = readBinary.ReadInt32()
});
}

Expand Down
2 changes: 1 addition & 1 deletion SoG_SGreader/DataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void WriteToFile(string fileName)

writeBinary.Write(playerObject.PlayTimeTotal); // check for overflow

writeBinary.Write((byte )playerObject.PhaseShiftStuff);
writeBinary.Write((byte)playerObject.PhaseShiftStuff);

writeBinary.Write((ushort) playerObject.CharacterFlags.Count);
for (int i = 0; i != playerObject.CharacterFlags.Count; i++)
Expand Down
63 changes: 63 additions & 0 deletions SoG_SGreader/Enum/DynamicEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoG_SGreader.Enum
{
public class DynamicEnum
{
private readonly string filePath;
private Dictionary<string, int> nameToValue = new Dictionary<string, int>();
private Dictionary<int, string> valueToName = new Dictionary<int, string>();

public DynamicEnum(string filePath, string key)
{
var jsonData = File.ReadAllText(filePath);
var items = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, int>>>(jsonData);
if (items != null && items.ContainsKey(key))
{
foreach (var item in items[key])
{
nameToValue[RemoveLeadingUnderscore(item.Key)] = item.Value;
valueToName[item.Value] = RemoveLeadingUnderscore(item.Key);
}
}
else
{
throw new KeyNotFoundException($"The key '{key}' is not found in the JSON data.");
}
}

public int GetValue(string name)
{
if (nameToValue.ContainsKey(name))
{
return nameToValue[name];
}
throw new KeyNotFoundException($"The name '{name}' is not found in the {filePath} enum.");
}

public string GetName(int value)
{
if (valueToName.ContainsKey(value))
{
return valueToName[value];
}
throw new KeyNotFoundException($"The value '{value}' is not found in the {filePath} enum.");
}

public IEnumerable<string> GetNames()
{
return nameToValue.Keys;
}

private static string RemoveLeadingUnderscore(string input)
{
return input.StartsWith("_") ? input.Substring(1) : input;
}
}
}
18 changes: 18 additions & 0 deletions SoG_SGreader/Enum/GameEnums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoG_SGreader.Enum
{
public static class GameEnums
{
public static DynamicEnum SogItem;

public static void InitializeEnums()
{
SogItem = new DynamicEnum("ItemTypes.json", "ItemTypes");
}
}
}
53 changes: 0 additions & 53 deletions SoG_SGreader/Enum/SogFish.cs

This file was deleted.

Loading