Skip to content

Commit

Permalink
Complete transition away from ark-tools
Browse files Browse the repository at this point in the history
Use ark-data for species names
Use custom coordinate transforms
  • Loading branch information
coldino committed Nov 14, 2018
1 parent 950f6e0 commit 410194a
Show file tree
Hide file tree
Showing 18 changed files with 612 additions and 291 deletions.
18 changes: 18 additions & 0 deletions Larkator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SavegameToolkit", "ArkSaveg
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SavegameToolkitAdditions", "ArkSavegameToolkit\SavegameToolkitAdditions\SavegameToolkitAdditions.csproj", "{CA24E3C7-3BEE-4774-977E-E9253352CFB2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MapCalibrator", "MapCalibrator\MapCalibrator.csproj", "{AA6DF52F-AECA-465B-B45B-14D18DB7F411}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -112,6 +114,22 @@ Global
{CA24E3C7-3BEE-4774-977E-E9253352CFB2}.Release|x64.Build.0 = Release|Any CPU
{CA24E3C7-3BEE-4774-977E-E9253352CFB2}.Release|x86.ActiveCfg = Release|Any CPU
{CA24E3C7-3BEE-4774-977E-E9253352CFB2}.Release|x86.Build.0 = Release|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Debug|ARM.ActiveCfg = Debug|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Debug|ARM.Build.0 = Debug|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Debug|x64.ActiveCfg = Debug|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Debug|x64.Build.0 = Debug|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Debug|x86.ActiveCfg = Debug|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Debug|x86.Build.0 = Debug|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Release|Any CPU.Build.0 = Release|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Release|ARM.ActiveCfg = Release|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Release|ARM.Build.0 = Release|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Release|x64.ActiveCfg = Release|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Release|x64.Build.0 = Release|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Release|x86.ActiveCfg = Release|Any CPU
{AA6DF52F-AECA-465B-B45B-14D18DB7F411}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
58 changes: 33 additions & 25 deletions LarkatorGUI/ArkReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace LarkatorGUI
{
public class ArkReader
{
public int MapSize { get; set; } = 8000;
public MapCalibration MapCalibration { get; set; }

public Dictionary<string, List<Dino>> WildDinos { get; } = new Dictionary<string, List<Dino>>();
public Dictionary<string, List<Dino>> TamedDinos { get; } = new Dictionary<string, List<Dino>>();
Expand All @@ -22,10 +22,18 @@ public class ArkReader
public List<string> WildSpecies { get; } = new List<string>();
public int NumberOfTamedSpecies { get => TamedSpecies.Count; }
public int NumberOfWildSpecies { get => WildSpecies.Count; }

private ArkData arkData;

public void SetArkData(ArkData data)
{
arkData = data;

// Create some easy to use mappings for better performance
classMap = arkData.Creatures.ToDictionary(c => c.Class, c => c.Name);
}

private static readonly string[] RAFT_CLASSES = { "Raft_BP_C", "MotorRaft_BP_C", "Barge_BP_C" };
private ArkData arkData;
private Dictionary<string, string> classMap;

private static Task<(GameObjectContainer gameObjects, float gameTime)> ReadSavegameFile(string fileName)
{
Expand Down Expand Up @@ -64,6 +72,9 @@ public class ArkReader

public async Task PerformConversion(string saveFile)
{
if (MapCalibration == null)
throw new ArgumentNullException(nameof(MapCalibration), "Callibration required");

// Clear previously loaded data
TamedSpecies.Clear();
WildSpecies.Clear();
Expand All @@ -78,33 +89,41 @@ public async Task PerformConversion(string saveFile)
var creatureObjects = gameObjectContainer
.Where(o => o.IsCreature() && !o.IsUnclaimedBaby() && !RAFT_CLASSES.Contains(o.ClassString))
.ToList();
var tameObjects = creatureObjects.Where(o => !o.IsWild()).GroupBy(o => o.ClassString);
TamedSpecies.AddRange(tameObjects.Select(o => o.Key));

var tameObjects = creatureObjects.Where(o => !o.IsWild()).GroupBy(o => SpeciesName(o.ClassString));
TamedSpecies.AddRange(tameObjects.Select(o => o.Key).Distinct());
foreach (var group in tameObjects)
TamedDinos.Add(group.Key, group.Select(o => ConvertCreature(o)).ToList());

var wildObjects = creatureObjects.Where(o => o.IsWild()).GroupBy(o => o.ClassString);
WildSpecies.AddRange(wildObjects.Select(o => o.Key));
var wildObjects = creatureObjects.Where(o => o.IsWild()).GroupBy(o => SpeciesName(o.ClassString));
WildSpecies.AddRange(wildObjects.Select(o => o.Key).Distinct());
foreach (var group in wildObjects)
WildDinos.Add(group.Key, group.Select(o => ConvertCreature(o)).ToList());

AllSpecies.AddRange(creatureObjects.Select(o => o.ClassString).Distinct());
AllSpecies.AddRange(creatureObjects.Select(o => SpeciesName(o.ClassString)).Distinct());
}

private string SpeciesName(string className)
{
if (classMap.TryGetValue(className, out var output))
return output;

return className;
}

private Dino ConvertCreature(GameObject obj)
{
var dino = new Dino
{
Type = obj.ClassString,
Type = SpeciesName(obj.ClassString),
Female = obj.IsFemale(),
Id = (ulong)obj.GetDinoId(),
BaseLevel = obj.GetBaseLevel(),
Name = obj.GetPropertyValue("TamedName", defaultValue:""),
Name = obj.GetPropertyValue("TamedName", defaultValue: ""),
Location = ConvertCoordsToLatLong(obj.Location),
WildLevels = new StatPoints(),
};

var status = obj.CharacterStatusComponent();
if (status != null)
{
Expand All @@ -127,22 +146,11 @@ private Position ConvertCoordsToLatLong(LocationData location)
Y = location.Y,
Z = location.Z,

Lat = 50 + location.Y / 8000,
Lon = 50 + location.X / 8000,
Lat = MapCalibration.LatOffset + location.Y / MapCalibration.LatDivisor,
Lon = MapCalibration.LonOffset + location.X / MapCalibration.LonDivisor,
};
}

private bool IsConversionRequired()
{
return true;

//var classFile = Path.Combine(outputDir, Properties.Resources.ClassesJson);
//if (!File.Exists(classFile)) return true;
//var arkTimestamp = File.GetLastWriteTimeUtc(Properties.Settings.Default.SaveFile);
//var convertTimestamp = File.GetLastWriteTimeUtc(classFile);
//return (arkTimestamp >= convertTimestamp);
}

private string GenerateNameVariant(string name, string cls)
{
var clsParts = cls.Split('_');
Expand Down
24 changes: 16 additions & 8 deletions LarkatorGUI/CalibrationWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
<TextBlock Text="Y1" Margin="8,2"/>
<TextBox Text="{Binding Bounds.Y2, Mode=TwoWay}" Width="64"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4">
<TextBlock Text="Lat +" Margin="8,2"/>
<TextBox Text="{Binding LatOffset, Mode=TwoWay}" Width="64"/>
<TextBlock Text="/" Margin="8,2"/>
<TextBox Text="{Binding LatDivisor, Mode=TwoWay}" Width="64"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4">
<TextBlock Text="Lon +" Margin="8,2"/>
<TextBox Text="{Binding LonOffset, Mode=TwoWay}" Width="64"/>
<TextBlock Text="/" Margin="8,2"/>
<TextBox Text="{Binding LonDivisor, Mode=TwoWay}" Width="64"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4">
<TextBlock Text="ARK filename" Margin="8,2"/>
<TextBox Text="{Binding Filename, Mode=TwoWay}" Width="100" TextChanged="Filename_TextChanged"/>
Expand All @@ -43,17 +55,13 @@
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4">
<TextBlock Text="+X" Margin="8,2"/>
<TextBox Text="{Binding OffsetX}" Width="32"/>
<TextBox Text="{Binding PixelOffsetX}" Width="32"/>
<TextBlock Text="+Y" Margin="8,2"/>
<TextBox Text="{Binding OffsetY}" Width="32"/>
<TextBox Text="{Binding PixelOffsetY}" Width="32"/>
<TextBlock Text="*X" Margin="8,2"/>
<TextBox Text="{Binding ScaleX}" Width="64"/>
<TextBox Text="{Binding PixelScaleX}" Width="64"/>
<TextBlock Text="*Y" Margin="8,2"/>
<TextBox Text="{Binding ScaleY}" Width="64"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4">
<TextBlock Text="Units" Margin="8,2"/>
<TextBox Text="{Binding Units, Mode=TwoWay}" Width="60" TextChanged="UpdateOutput_TextChanged"/>
<TextBox Text="{Binding PixelScaleY}" Width="64"/>
</StackPanel>
</StackPanel>
<TextBox Grid.Row="1" Text="{Binding Output}" Margin="8" MinWidth="150" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" IsReadOnly="True"/>
Expand Down
108 changes: 72 additions & 36 deletions LarkatorGUI/CalibrationWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public ExampleCalibration()

public class Calibration : DependencyObject
{
public Calibration()
{
LatDivisor = LonDivisor = 8000;
LatOffset = LonOffset = 50;
}

public Bounds Bounds
{
get { return (Bounds)GetValue(BoundsProperty); }
Expand All @@ -110,34 +116,52 @@ public string Image
set { SetValue(ImageProperty, value); }
}

public int Units
public double PixelOffsetX
{
get { return (double)GetValue(PixelOffsetXProperty); }
set { SetValue(PixelOffsetXProperty, value); }
}

public double PixelOffsetY
{
get { return (double)GetValue(PixelOffsetYProperty); }
set { SetValue(PixelOffsetYProperty, value); }
}

public double PixelScaleX
{
get { return (int)GetValue(UnitsProperty); }
set { SetValue(UnitsProperty, value); }
get { return (double)GetValue(PixelScaleXProperty); }
set { SetValue(PixelScaleXProperty, value); }
}

public double OffsetX
public double PixelScaleY
{
get { return (double)GetValue(OffsetXProperty); }
set { SetValue(OffsetXProperty, value); }
get { return (double)GetValue(PixelScaleYProperty); }
set { SetValue(PixelScaleYProperty, value); }
}

public double OffsetY
public double LatOffset
{
get { return (double)GetValue(OffsetYProperty); }
set { SetValue(OffsetYProperty, value); }
get { return (double)GetValue(LatOffsetProperty); }
set { SetValue(LatOffsetProperty, value); }
}

public double ScaleX
public double LonOffset
{
get { return (double)GetValue(ScaleXProperty); }
set { SetValue(ScaleXProperty, value); }
get { return (double)GetValue(LonOffsetProperty); }
set { SetValue(LonOffsetProperty, value); }
}

public double ScaleY
public double LatDivisor
{
get { return (double)GetValue(ScaleYProperty); }
set { SetValue(ScaleYProperty, value); }
get { return (double)GetValue(LatDivisorProperty); }
set { SetValue(LatDivisorProperty, value); }
}

public double LonDivisor
{
get { return (double)GetValue(LonDivisorProperty); }
set { SetValue(LonDivisorProperty, value); }
}

public string Output
Expand All @@ -149,24 +173,33 @@ public string Output
public static readonly DependencyProperty OutputProperty =
DependencyProperty.Register("Output", typeof(string), typeof(Calibration), new PropertyMetadata(""));

public static readonly DependencyProperty ScaleYProperty =
DependencyProperty.Register("ScaleY", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));
public static readonly DependencyProperty LonDivisorProperty =
DependencyProperty.Register("LonDivisor", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));

public static readonly DependencyProperty ScaleXProperty =
DependencyProperty.Register("ScaleX", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));
public static readonly DependencyProperty LatDivisorProperty =
DependencyProperty.Register("LatDivisor", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));

public static readonly DependencyProperty OffsetYProperty =
DependencyProperty.Register("OffsetY", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));
public static readonly DependencyProperty LonOffsetProperty =
DependencyProperty.Register("LonOffset", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));

public static readonly DependencyProperty OffsetXProperty =
DependencyProperty.Register("OffsetX", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));
public static readonly DependencyProperty LatOffsetProperty =
DependencyProperty.Register("LatOffset", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));

public static readonly DependencyProperty ImageProperty =
DependencyProperty.Register("Image", typeof(string), typeof(Calibration), new PropertyMetadata(""));
public static readonly DependencyProperty PixelScaleYProperty =
DependencyProperty.Register("PixelScaleY", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));

public static readonly DependencyProperty UnitsProperty =
DependencyProperty.Register("Units", typeof(int), typeof(Calibration), new PropertyMetadata(0));
public static readonly DependencyProperty PixelScaleXProperty =
DependencyProperty.Register("PixelScaleX", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));

public static readonly DependencyProperty PixelOffsetYProperty =
DependencyProperty.Register("PixelOffsetY", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));

public static readonly DependencyProperty PixelOffsetXProperty =
DependencyProperty.Register("PixelOffsetX", typeof(double), typeof(Calibration), new PropertyMetadata(0.0));

public static readonly DependencyProperty ImageProperty =
DependencyProperty.Register("Image", typeof(string), typeof(Calibration), new PropertyMetadata(""));

public static readonly DependencyProperty FilenameProperty =
DependencyProperty.Register("Filename", typeof(string), typeof(Calibration), new PropertyMetadata(""));

Expand All @@ -182,11 +215,11 @@ public void Recalculate()
var maxX = Math.Max(Bounds.X1, Bounds.X2);
var maxY = Math.Max(Bounds.Y1, Bounds.Y2);

ScaleX = (maxX - minX) / 80.0;
ScaleY = (maxY - minY) / 80.0;
PixelScaleX = (maxX - minX) / 80.0;
PixelScaleY = (maxY - minY) / 80.0;

OffsetX = minX - ScaleX * 10;
OffsetY = minY - ScaleY * 10;
PixelOffsetX = minX - PixelScaleX * 10;
PixelOffsetY = minY - PixelScaleY * 10;

Output = RecreateOutput();
}
Expand All @@ -195,11 +228,14 @@ private string RecreateOutput()
{
return $"{{\n" +
$" \"Filename\": \"{Filename}\",\n" +
$" \"Units\": {Units},\n" +
$" \"OffsetX\": {OffsetX},\n" +
$" \"OffsetY\": {OffsetY},\n" +
$" \"ScaleX\": {ScaleX},\n" +
$" \"ScaleY\": {ScaleY}\n" +
$" \"LatOffset\": {LatOffset},\n" +
$" \"LatDivisor\": {LatDivisor},\n" +
$" \"LonOffset\": {LonOffset},\n" +
$" \"LonDivisor\": {LonDivisor},\n" +
$" \"PixelOffsetX\": {PixelOffsetX},\n" +
$" \"PixelOffsetY\": {PixelOffsetY},\n" +
$" \"PixelScaleX\": {PixelScaleX},\n" +
$" \"PixelScaleY\": {PixelScaleY}\n" +
$"}},";
}
}
Expand Down
17 changes: 0 additions & 17 deletions LarkatorGUI/DirectoryEntryBox.xaml

This file was deleted.

Loading

0 comments on commit 410194a

Please sign in to comment.