Skip to content

Commit

Permalink
feat(Native): add SaveGame log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Jan 20, 2024
1 parent d58dfc0 commit db4992c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 0 deletions.
30 changes: 30 additions & 0 deletions ZenKit.Test/TestSaveGame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace ZenKit.Test;
Expand Down Expand Up @@ -38,4 +39,33 @@ public void TestLoadG1()
// Try to parse the world data.
var wld = sav.LoadWorld();
}

[Test]
public void TestLoadG2()
{
var sav = new SaveGame(GameVersion.Gothic2);
sav.Load("./Samples/G2/Save");

var meta = sav.Metadata;
Assert.That(meta.Title, Is.EqualTo("uwuowo"));
Assert.That(meta.World, Is.EqualTo("NEWWORLD"));
Assert.That(meta.TimeDay, Is.EqualTo(0));
Assert.That(meta.TimeHour, Is.EqualTo(12));
Assert.That(meta.TimeMinute, Is.EqualTo(28));
Assert.That(meta.SaveDate, Is.EqualTo("28.12.2022 - 18:26"));
Assert.That(meta.VersionMajor, Is.EqualTo(2));
Assert.That(meta.VersionMinor, Is.EqualTo(6));
Assert.That(meta.PlayTime.TotalSeconds, Is.EqualTo(1277));
Assert.That(meta.VersionPoint, Is.EqualTo(0));
Assert.That(meta.VersionInt, Is.EqualTo(0));
Assert.That(meta.VersionAppName, Is.EqualTo("Gothic II - 2.6 (fix)"));

var state = sav.State;
Assert.That(state.Day, Is.EqualTo(0));
Assert.That(state.Hour, Is.EqualTo(12));
Assert.That(state.Minute, Is.EqualTo(28));

// Try to parse the world data.
var wld = sav.LoadWorld();
}
}
11 changes: 11 additions & 0 deletions ZenKit/Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7352,6 +7352,17 @@ public static extern void ZkSaveState_addLogTopic(UIntPtr slf, string descriptio
[DllImport(DllName)]
public static extern void ZkSaveState_setGuildAttitudes(UIntPtr slf, byte[] attitudes, ulong dimension);

[DllImport(DllName)]
public static extern ulong ZkSaveState_getLogTopicEntryCount(UIntPtr slf, ulong iTopic);

[DllImport(DllName)]
public static extern IntPtr ZkSaveState_getLogTopicEntry(UIntPtr slf, ulong iTopic, ulong i);

[DllImport(DllName)]
public static extern void ZkSaveState_addLogTopicEntry(UIntPtr slf, ulong iTopic, string description);

[DllImport(DllName)]
public static extern void ZkSaveState_clearLogTopicEntries(UIntPtr slf, ulong iTopic);

public class Callbacks
{
Expand Down
13 changes: 13 additions & 0 deletions ZenKit/SaveGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public struct SaveLogTopic
public string Description;
public SaveTopicSection Section;
public SaveTopicStatus Status;
public List<string> Entries;
}


Expand Down Expand Up @@ -369,18 +370,30 @@ public SaveLogTopic GetLogTopic(int i)

Native.ZkSaveState_getLogTopic(_handle, (ulong)i, out var name, out topic.Section, out topic.Status);
topic.Description = name.MarshalAsString() ?? string.Empty;
topic.Entries = new List<string>();

var count = Native.ZkSaveState_getLogTopicEntryCount(_handle, (ulong)i);
for (var j = 0u; j < count; ++j) {
var s = Native.ZkSaveState_getLogTopicEntry(_handle, (ulong)i, j).MarshalAsString();
if (s == null) continue;
topic.Entries.Add(s);
}

return topic;
}

public void SetLogTopic(int i, SaveLogTopic state)
{
Native.ZkSaveState_setLogTopic(_handle, (ulong)i, state.Description, state.Section, state.Status);
Native.ZkSaveState_clearLogTopicEntries(_handle, (ulong)i);
state.Entries.ForEach(v => Native.ZkSaveState_addLogTopicEntry(_handle, (ulong)i, v));
}

public void AddLogTopic(SaveLogTopic state)
{
Native.ZkSaveState_addLogTopic(_handle, state.Description, state.Section, state.Status);
Native.ZkSaveState_clearLogTopicEntries(_handle, (ulong)(LogTopicCount - 1));
state.Entries.ForEach(v => Native.ZkSaveState_addLogTopicEntry(_handle, (ulong)(LogTopicCount - 1), v));
}

public void RemoveLogTopic(int i)
Expand Down
Binary file modified ZenKit/runtimes/android-arm64/native/libzenkitcapi.so
Binary file not shown.
Binary file modified ZenKit/runtimes/linux-x64/native/libzenkitcapi.so
Binary file not shown.
Binary file modified ZenKit/runtimes/osx-x64/native/libzenkitcapi.dylib
Binary file not shown.
Binary file modified ZenKit/runtimes/win-x64/native/zenkitcapi.dll
Binary file not shown.

0 comments on commit db4992c

Please sign in to comment.