Skip to content

Commit

Permalink
string parsing for cargo and stretlight, show group icons in tree view
Browse files Browse the repository at this point in the history
  • Loading branch information
LeftofZen committed Oct 24, 2023
1 parent b16dcb8 commit 7cafa9b
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 62 deletions.
1 change: 1 addition & 0 deletions OpenLocoTool/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public static class Constants
{
public const int LocoDatFileFlag = 0x11;
public const int G1ObjectTabsOffset = 3505; // see ImageIds.h in openloco
}
}
10 changes: 10 additions & 0 deletions OpenLocoTool/DatFileParsing/LocoObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ public G1Dat(G1Header g1Header, List<G1Element32> g1Elements)
public List<G1Element32> G1Elements { get; set; }
}

//public class ByteLocoObject
//{
// public byte[] S5Header { get; }
// public byte[] ObjectHeader { get; set; }
// public byte[] Object { get; set; }
// public byte[] StringTable { get; set; }
// public byte[] G1Header { get; set; }
// public byte[] G1Elements { get; set; }
//}

[TypeConverter(typeof(ExpandableObjectConverter))]
public class LocoObject : ILocoObject
{
Expand Down
12 changes: 6 additions & 6 deletions OpenLocoTool/DatFileParsing/SawyerStreamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,28 +268,28 @@ public static byte[] DecodeRLEImageData(G1Element32 img)
return dstBuf;
}

public byte[] LoadBytesFromFile(string filename)
public static byte[] LoadBytesFromFile(string filename)
{
if (!File.Exists(filename))
{
Logger.Log(LogLevel.Error, $"Path doesn't exist: {filename}");
//Logger.Log(LogLevel.Error, $"Path doesn't exist: {filename}");
throw new InvalidOperationException($"File doesn't exist: {filename}");
}

Logger.Log(LogLevel.Info, $"Loading {filename}");
//Logger.Log(LogLevel.Info, $"Loading {filename}");
return File.ReadAllBytes(filename);
}

public S5Header LoadHeader(string filename)
public static S5Header LoadHeader(string filename)
{
if (!File.Exists(filename))
{
Logger.Log(LogLevel.Error, $"Path doesn't exist: {filename}");
//Logger.Log(LogLevel.Error, $"Path doesn't exist: {filename}");

throw new InvalidOperationException($"File doesn't exist: {filename}");
}

Logger.Log(LogLevel.Info, $"Loading header for {filename}");
//Logger.Log(LogLevel.Info, $"Loading header for {filename}");
var size = S5Header.StructLength;
var data = new byte[size];

Expand Down
7 changes: 7 additions & 0 deletions OpenLocoTool/DataFiles/ImageIds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenLocoTool.DataFiles
{
public static class ImageIds
{
// todo: import list from ImageIds.h in openloco
}
}
64 changes: 64 additions & 0 deletions OpenLocoTool/DataFiles/OriginalDataFiles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace OpenLocoTool.DataFiles
{
public static class OriginalDataFiles
{
public static readonly HashSet<string> Names = new()
{
"Data/g1.DAT",
"plugin.dat",
"plugin2.dat",
"Data/CSS1.DAT",
"Data/CSS2.DAT",
"Data/CSS3.DAT",
"Data/CSS4.DAT",
"Data/CSS5.DAT",
"game.cfg",
"Data/KANJI.DAT",
"Data/20s1.DAT",
"Data/20s2.DAT",
"Data/20s4.DAT",
"Data/50s1.DAT",
"Data/50s2.DAT",
"Data/70s1.DAT",
"Data/70s2.DAT",
"Data/70s3.DAT",
"Data/80s1.DAT",
"Data/90s1.DAT",
"Data/90s2.DAT",
"Data/rag3.DAT",
"Data/Chrysanthemum.DAT",
"Data/Eugenia.DAT",
"Data/Rag2.DAT",
"Data/Rag1.DAT",
"Data/20s3.DAT",
"Data/40s1.DAT",
"Data/40s2.DAT",
"Data/50s3.DAT",
"Data/40s3.DAT",
"Data/80s2.DAT",
"Data/60s1.DAT",
"Data/80s3.DAT",
"Data/60s2.DAT",
"Data/60s3.DAT",
"Data/80s4.DAT",
"Data/20s5.DAT",
"Data/20s6.DAT",
"Data/title.dat",
"scores.dat",
"Scenarios/Boulder Breakers.SC5",
"Data/TUT1024_1.DAT",
"Data/TUT1024_2.DAT",
"Data/TUT1024_3.DAT",
"Data/TUT800_1.DAT",
"Data/TUT800_2.DAT",
"Data/TUT800_3.DAT",
"openloco.yml",
"language",
"save",
"save/autosave",
"1.TMP",
"ObjData",
"Scenarios",
};
}
}
62 changes: 62 additions & 0 deletions OpenLocoTool/DataFiles/OriginalDataPathIds.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
namespace OpenLocoTool.DataFiles
{
// these are indexed to the strings in OriginalDateFiles.cs
public enum OriginalDataPathIds : uint8_t
{
g1,
plugin1,
plugin2,
css1, // Sound effects
css2, // Wind (mountains)
css3, // Ocean
css4, // Jungle
css5, // Title music
gamecfg,
kanji,
music_chuggin_along,
music_long_dusty_road,
music_flying_high,
music_gettin_on_the_gas,
music_jumpin_the_rails,
music_smooth_running,
music_traffic_jam,
music_never_stop_til_you_get_there,
music_soaring_away,
music_techno_torture,
music_everlasting_high_rise,
music_solace,
music_chrysanthemum,
music_eugenia,
music_the_ragtime_dance,
music_easy_winners,
music_setting_off,
music_a_travellers_serenade,
music_latino_trip,
music_a_good_head_of_steam,
music_hop_to_the_bop,
music_the_city_lights,
music_steamin_down_town,
music_bright_expectations,
music_mo_station,
music_far_out,
music_running_on_time,
music_get_me_to_gladstone_bay,
music_sandy_track_blues,
title,
scores,
boulderBreakers,
tut1024_1,
tut1024_2,
tut1024_3,
tut800_1,
tut800_2,
tut800_3,
openlocoYML,
languageFiles,
save,
autosave,
_1tmp,
objects,
scenarios,
};
}
1 change: 1 addition & 0 deletions OpenLocoTool/Headers/S5Header.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace OpenLocoTool.Headers
public enum SourceGame : byte
{
Custom = 0,
DataFile = 1,
Vanilla = 2,
}

Expand Down
14 changes: 11 additions & 3 deletions OpenLocoTool/Objects/CargoObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public record CargoObject(
//[property: LocoStructOffset(0x00)] string_id Name,
[property: LocoStructOffset(0x02)] uint16_t var_02,
[property: LocoStructOffset(0x04)] uint16_t var_04,
[property: LocoStructOffset(0x06)] string_id UnitsAndCargoName,
[property: LocoStructOffset(0x08)] string_id UnitNameSingular,
[property: LocoStructOffset(0x0A)] string_id UnitNamePlural,
//[property: LocoStructOffset(0x06)] string_id UnitsAndCargoName,
//[property: LocoStructOffset(0x08)] string_id UnitNameSingular,
//[property: LocoStructOffset(0x0A)] string_id UnitNamePlural,
[property: LocoStructOffset(0x0C)] uint32_t UnitInlineSprite,
[property: LocoStructOffset(0x10)] uint16_t MatchFlags,
[property: LocoStructOffset(0x12)] CargoObjectFlags Flags,
Expand All @@ -40,10 +40,18 @@ public record CargoObject(
public static int StructSize => 0x1F;

public string Name { get; set; }
public string UnitsAndCargoName { get; set; }

public string UnitNameSingular { get; set; }

public string UnitNamePlural { get; set; }

public void LoadPostStringTable(StringTable stringTable)
{
Name = stringTable[(0, (LanguageId)0)];
UnitsAndCargoName = stringTable[(1, (LanguageId)0)];
UnitNameSingular = stringTable[(2, (LanguageId)0)];
UnitNamePlural = stringTable[(3, (LanguageId)0)];
}
}
}
13 changes: 13 additions & 0 deletions OpenLocoTool/Objects/StreetLightObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,17 @@ public record StreetLightObject(
public static int StructSize => 0x0C;
public const int DesignedYearLength = 3;
}

//public class StreetLightObject2 : LocoObject
//{
// public StreeLightObject2(S5Header s5Hdr, ObjectHeader objHdr, ILocoStruct obj, StringTable stringTable, G1Header g1Header, List<G1Element32> g1Elements) : base(s5Hdr, objHdr, obj, stringTable, g1Header, g1Elements)
// {
// }

// public string Name { get; set; }
// public uint16_t DesignedYear { get; set; }

// public G1Element32 Image { get; set; }

//}
}
Loading

0 comments on commit 7cafa9b

Please sign in to comment.