Skip to content

Commit

Permalink
Remove "Debug_ReadonlyMode" debug config, add -readonlyMode app arg;
Browse files Browse the repository at this point in the history
Add -language=xx add arg;
Add item inventory feature, add item count display (achievement);
Add place color;
  • Loading branch information
LonelyWindG committed Mar 29, 2023
1 parent d75f387 commit b5692ad
Show file tree
Hide file tree
Showing 23 changed files with 737 additions and 189 deletions.
3 changes: 0 additions & 3 deletions OctopathTraveler.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OctopathTraveler", "Octopat
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_ReadonlyMode|Any CPU = Debug_ReadonlyMode|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{743327B0-C335-4575-AC5D-F59B2680BCF7}.Debug_ReadonlyMode|Any CPU.ActiveCfg = Debug_ReadonlyMode|Any CPU
{743327B0-C335-4575-AC5D-F59B2680BCF7}.Debug_ReadonlyMode|Any CPU.Build.0 = Debug_ReadonlyMode|Any CPU
{743327B0-C335-4575-AC5D-F59B2680BCF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{743327B0-C335-4575-AC5D-F59B2680BCF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{743327B0-C335-4575-AC5D-F59B2680BCF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
3 changes: 2 additions & 1 deletion OctopathTraveler/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:OctopathTraveler"
StartupUri="MainWindow.xaml">
StartupUri="MainWindow.xaml"
Startup="App_Startup">
<Application.Resources>
<BitmapImage x:Key="Open" UriSource="./Resource/Open.png"/>
<BitmapImage x:Key="Save" UriSource="./Resource/Save.png"/>
Expand Down
106 changes: 95 additions & 11 deletions OctopathTraveler/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,101 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Windows;

namespace OctopathTraveler
{
/// <summary>
/// App.xaml の相互作用ロジック
/// </summary>
public partial class App : Application
{
}
/// <summary>
/// App.xaml の相互作用ロジック
/// </summary>
public partial class App : Application
{
private void App_Startup(object sender, StartupEventArgs e)
{
#if !DEBUG
Application.Current.DispatcherUnhandledException += OnDispatcherUnhandledException;
#endif

for (int i = 0; i < e.Args.Length; i++)
{
string arg = e.Args[i];
Trace.WriteLine($"Startup arg[{i}]: {arg}");
if (arg.StartsWith("-language="))
{
SetLanguage(arg["-language=".Length..]);
continue;
}

if (arg == "-readonlyMode")
{
SaveData.IsReadonlyMode = true;
}
}
}

private static void SetLanguage(string language)
{
try
{
CultureInfo cultureInfo;
language = language.ToLower();
switch (language)
{
case "zh-cn":
case "zh_cn":
cultureInfo = CultureInfo.GetCultureInfo("zh-CN");
break;
case "ja-jp":
case "ja_jp":
cultureInfo = CultureInfo.GetCultureInfo("ja-JP");
break;
case "en-us":
case "en_us":
cultureInfo = CultureInfo.GetCultureInfo("en-US");
break;
default:
if (language.StartsWith("en"))
{
cultureInfo = CultureInfo.GetCultureInfo("en-US");
break;
}
return;
}
CultureInfo.CurrentUICulture = cultureInfo;
OctopathTraveler.Properties.Resources.Culture = cultureInfo;
}
catch
{
}
}

private static void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
try
{
if (e.Handled)
return;

HandleException(e.Exception);
}
finally
{
e.Handled = true;
}
}

private static void HandleException(Exception exception)
{
string ex = exception.ToString();
try
{
File.AppendAllText("exception.log", DateTime.Now.ToString() + "\n" + ex + "\n");
}
catch (Exception)
{
}
MessageBox.Show(ex, "Program Exception");
}
}
}
27 changes: 26 additions & 1 deletion OctopathTraveler/BasicData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using System.ComponentModel;
using System.Diagnostics;

namespace OctopathTraveler
{
Expand Down Expand Up @@ -52,6 +52,8 @@ public uint HiddenPointCount
set => Util.WriteNumber(_hiddenPointCountAddress, 4, value, 0, 152);
}

public string ItemCount { get; private set; } = "0/579";

public BasicData()
{
var save = SaveData.Instance();
Expand Down Expand Up @@ -87,6 +89,29 @@ public BasicData()

gvas.AppendValue(Util.FindFirstAddress("HiddenPointCount", achievementAddress));
_hiddenPointCountAddress = gvas.Key("HiddenPointCount").Address;

gvas = new GVAS(null);
gvas.AppendValue(Util.FindFirstAddress("ItemFlag", achievementAddress));

int itemCount = 0;
int flagIndex = 0;
string flagKey = "ItemFlag_" + flagIndex;
while (gvas.HasKey(flagKey))
{
uint flags = gvas.ReadNumber(flagKey);
for (int i = 0; i < 32; i++)
{
if (((flags >> i) & 1) == 1)
{
itemCount++;
}
}

flagIndex++;
flagKey = "ItemFlag_" + flagIndex;
}

ItemCount = itemCount + "/579";
}
}
}
32 changes: 19 additions & 13 deletions OctopathTraveler/DataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,27 @@ public DataContext()
Charactors.Add(chara);
}

int zeroIdCount = 0;
var ownedItemIds = new HashSet<uint>();
var items = new List<Item>(Info.Instance().Items.Count);
foreach (var address in save.FindAddress("ItemID_", 0))
{
var item = new Item(address);
if (item.ID == 0)
if (item.ID == 0 && zeroIdCount++ > 8)
continue;

items.Add(item);
if (item.Count > 0)
ownedItemIds.Add(item.ID);
}
items.Sort((x, y) => x.ID.CompareTo(y.ID));
Items = new ObservableCollection<Item>(items);

foreach (var item in Info.ItemInventory)
{
item.IsOwned = ownedItemIds.Contains(item.Value);
}

var gvas = new GVAS(null);
gvas.AppendValue(save.FindAddress("MainMemberID_", 0).First());
for (uint i = 0; i < 4; i++)
Expand Down Expand Up @@ -87,18 +96,17 @@ public DataContext()
var data = gvas.Key("VisitedMap_" + i.ToString());
for (uint size = 0; size < data.Size; size++)
{
for (uint bit = 0; bit < 8; bit++)
for (uint bit = 0; bit < 8; bit++, id++)
{
if (id < 12)//Ignore the first 12, as these values are all 0
{
id++;
continue;
}

var info = Info.Search(Info.Instance().Places, id);
var place = new Place(data.Address + size, bit, info?.Name ?? $"{id}(0x{id:X})({data.Address + size + bit})");
Places.Add(place);
id++;
uint placeAddress = data.Address + size;
if (info == null && !Place.IsVisit(placeAddress, bit))
continue;

Places.Add(new Place(placeAddress, bit, info ?? new PlaceInfo { Value = id, Name = "UNKNOWN" }));
}
}
}
Expand All @@ -118,15 +126,13 @@ public DataContext()
//gvas.AppendValue(treasures[i]);
uint tid = checked((uint)((int)treasures[i] - diff));
var info = Info.Search(Info.Instance().TreasureStates, tid);
#if DEBUG
info ??= new TreasureStateInfo { Value = tid };
#endif
if (info == null)
continue;

uint treausreAddress = treasures[i] + 100;
if (tid == 1277013)
{
Trace.Write($"{i + 1}/{treasures.Count}");
}

//var data = gvas.Key("TreasureStateArray_" + i);
var treasure = new TreasureState(treausreAddress, info);
TreasureStates.Add(treasure);
Expand Down
78 changes: 43 additions & 35 deletions OctopathTraveler/Info.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Collections.Generic;
using MiniExcelLibs;
using OctopathTraveler.Properties;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Windows;
using MiniExcelLibs;
using OctopathTraveler.Properties;

namespace OctopathTraveler
{
Expand All @@ -13,11 +12,12 @@ class Info

private static Info mThis;
public List<NameValueInfo> Items { get; private set; } = new List<NameValueInfo>();
public List<InventoryItemInfo> ItemInventory { get; private set; } = new List<InventoryItemInfo>();
public List<NameValueInfo> CharaNames { get; private set; } = new List<NameValueInfo>();
public List<NameValueInfo> Jobs { get; private set; } = new List<NameValueInfo>();
public List<NameValueInfo> Equipments { get; private set; } = new List<NameValueInfo>();
public List<NameValueInfo> Countris { get; private set; } = new List<NameValueInfo>();
public List<NameValueInfo> Places { get; private set; } = new List<NameValueInfo>();
public List<PlaceInfo> Places { get; private set; } = new List<PlaceInfo>();
public List<EnemyInfo> Enemies { get; private set; } = new List<EnemyInfo>();
public List<TameMonsterInfo> TameMonsters { get; private set; } = new List<TameMonsterInfo>();
public List<TreasureStateInfo> TreasureStates { get; private set; } = new List<TreasureStateInfo>();
Expand All @@ -36,7 +36,7 @@ public static Info Instance()

public static string GetNameOrID2Hex<TInfo>(List<TInfo> list, uint id) where TInfo : NameValueInfo, new()
{
return Search(list, id)?.Name ?? $"{id}(0x{id:X})";
return id == 0 ? "0" : Search(list, id)?.Name ?? $"{id}(0x{id:X})";
}

public static TType Search<TType>(List<TType> list, uint id) where TType : NameValueInfo, new()
Expand All @@ -55,35 +55,11 @@ public static Info Instance()

private void Init()
{
byte[] excel;
var culture = Resources.Culture ?? CultureInfo.CurrentUICulture;

string file = $"info_{culture.Name.ToLower().Replace("-", "_")}.xlsx";
if (File.Exists(file))
{
LoadedInfoFile = "Info Excel Path: " + file.Replace("_", "__");
excel = File.ReadAllBytes(file);
}
else if (File.Exists("info.xlsx"))
{
LoadedInfoFile = "Info Excel Path: info.xlsx";
excel = File.ReadAllBytes("info.xlsx");
}
else
{
var resourceSet = Resources.ResourceManager.GetResourceSet(culture, true, false);
excel = resourceSet == null ? null : resourceSet.GetObject("InfoExcel") as byte[];
if (excel == null)
{
resourceSet = Resources.ResourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, false);
excel = resourceSet == null ? null : resourceSet.GetObject("InfoExcel") as byte[];
LoadedInfoFile = "Info Excel Path: Embedded Resource, Language: Unknown";
}
else
{
LoadedInfoFile = "Info Excel Path: Embedded Resource, Language: " + culture.Name;
}
}
byte[] excel = LoadExcel(false, culture);
excel ??= LoadExcel(false, null);
excel ??= LoadExcel(true, culture);
excel ??= LoadExcel(true, null);

if (excel == null || excel.Length <= 0)
{
Expand All @@ -93,6 +69,7 @@ private void Init()

var reader = new ExcelReader(excel);
reader.AppendListAndOrderByValue("item", Items);
reader.AppendList("item_inventory", ItemInventory);
reader.AppendListAndOrderByValue("character", CharaNames);
reader.AppendListAndOrderByValue("job", Jobs);
reader.AppendListAndOrderByValue("equipment", Equipments);
Expand All @@ -103,11 +80,42 @@ private void Init()
reader.AppendListAndOrderByValue("treasure_states", TreasureStates);
}

private static byte[] LoadExcel(bool embedded, CultureInfo culture)
{
bool isSpecificCulture = culture != null && !culture.Name.StartsWith("en", System.StringComparison.OrdinalIgnoreCase);
if (embedded)
{
var resourceSet = Resources.ResourceManager.GetResourceSet(isSpecificCulture ? culture : CultureInfo.InvariantCulture, true, false);
LoadedInfoFile = "Info Excel Path: Embedded Resource, Language: en";
return resourceSet == null ? null : resourceSet.GetObject("InfoExcel") as byte[];
}
else if (isSpecificCulture)
{
string file = $"info_{culture.Name.ToLower().Replace("-", "_")}.xlsx";
if (File.Exists(file))
{
LoadedInfoFile = "Info Excel Path: " + file.Replace("_", "__");
return File.ReadAllBytes(file);
}
}
else if (File.Exists("info.xlsx"))
{
LoadedInfoFile = "Info Excel Path: info.xlsx";
return File.ReadAllBytes("info.xlsx");
}
return null;
}

public static bool TryGetEmbeddedInfoExcel(out (string, byte[])[] excels)
{
var culture = Resources.Culture ?? CultureInfo.CurrentUICulture;
var cultureExcel = Resources.ResourceManager.GetResourceSet(culture, true, false)?.GetObject("InfoExcel") as byte[];
var invariantExcel = Resources.ResourceManager.GetResourceSet(CultureInfo.InvariantCulture, true, false)?.GetObject("InfoExcel") as byte[];
if (culture.Name.StartsWith("en", System.StringComparison.OrdinalIgnoreCase))
{
excels = new[] { ("info.xlsx", invariantExcel) };
return true;
}
var cultureExcel = Resources.ResourceManager.GetResourceSet(culture, true, false)?.GetObject("InfoExcel") as byte[];
if (invariantExcel != null && cultureExcel != null)
{
excels = new[]
Expand Down
Loading

0 comments on commit b5692ad

Please sign in to comment.