Skip to content

Commit

Permalink
experimental INT previewing
Browse files Browse the repository at this point in the history
  • Loading branch information
kran27 committed Dec 26, 2024
1 parent 44d5797 commit a66639d
Show file tree
Hide file tree
Showing 15 changed files with 3,695 additions and 3,607 deletions.
2 changes: 1 addition & 1 deletion VBExtender/imguimenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static long __stdcall detour_present(IDXGISwapChain* p_swap_chain, UINT sync_int

ImGuiIO& io = ImGui::GetIO();

if (GetAsyncKeyState(VK_INSERT) & 1) show = !show;
if (GetAsyncKeyState(VK_HOME) & 1) show = !show;

if (show != lastShow)
{
Expand Down
180 changes: 129 additions & 51 deletions VBLauncher/Classes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -903,49 +903,6 @@ public IEnumerable<byte> ToByte()

#region Other Classes

public class Point2
{
public float x;
public float y;

public Point2(float x, float y)
{
this.x = x;
this.y = y;
}

public IEnumerable<byte> ToByte()
{
var ret = new byte[8];
ret.Write(0, x);
ret.Write(4, y);
return ret;
}
}

public class Point3
{
public float x;
public float y;
public float z;

public Point3(float x, float z, float y)
{
this.x = x;
this.z = z;
this.y = y;
}

public IEnumerable<byte> ToByte()
{
var ret = new byte[12];
ret.Write(0, x);
ret.Write(4, z);
ret.Write(8, y);
return ret;
}
}

public class Skill
{
public int Index;
Expand Down Expand Up @@ -1749,38 +1706,159 @@ public static string[] AllEnumValues()

public class INT
{
enum flags
public enum flags
{
Stretch,
TileX,
TileY,
TileBoth,
}

public enum magic
{
Window,
Button,
Picture,
Label,
Edit,
}

public struct rect
{
public int x1;
public int y1;
public int x2;
public int y2;
}

public struct fragment
{
public int width;
public int height;
public string texture;
public int x1;
public int y1;
public int x2;
public int y2;
public rect rect;
}

public struct obj
{
public int magic;
public rect rect1;
public string name;
public string ini;
public rect rect2;
public List<fragment> fragments;
}

public string name = "";
public List<obj> objects = [];

public INT(byte[] b)
{
var ms = new MemoryStream();
ms.Write(b, 0, b.Length);
var br = new BinaryReader(ms);

var twofont = false;
var ret = new obj();
br.BaseStream.Seek(0, SeekOrigin.Begin);

// TODO: implement two font logic (uncertain my ImHex pattern handles properly)
// var twofont = false;

// any reads not marked with a comment are unknown values that may be stored later (assumed type)

br.ReadBytes(7); // header, ignore
var revision = br.ReadByte() - 0x30; // 0x30 to convert ASCII to int
var name_length = br.ReadInt32();
name = new string(br.ReadChars(name_length));
br.ReadByte();
br.ReadInt32();
while (br.BaseStream.Position < br.BaseStream.Length)
{
var obj = new obj();
obj.magic = br.ReadInt32();
if (obj.magic == 1)
{
if (revision == 3) {
// i have not researched this bit of data
br.ReadBytes(5);
var s1 = br.ReadInt32();
br.ReadBytes(s1);
var s2 = br.ReadInt32();
br.ReadBytes(s2);
var s3 = br.ReadInt32();
br.ReadBytes(s3);
}
else
{
br.ReadInt32();
}
}
obj.rect1 = new rect();
obj.rect1.x1 = br.ReadInt32();
obj.rect1.y1 = br.ReadInt32();
obj.rect1.x2 = br.ReadInt32();
obj.rect1.y2 = br.ReadInt32();
var name_length2 = br.ReadInt32();
obj.name = new string(br.ReadChars(name_length2));
br.ReadBytes(3);
var ini_length = br.ReadInt32();
obj.ini = new string(br.ReadChars(ini_length));
br.ReadBytes(4);
obj.rect2 = new rect();
obj.rect2.x1 = br.ReadInt32();
obj.rect2.y1 = br.ReadInt32();
obj.rect2.x2 = br.ReadInt32();
obj.rect2.y2 = br.ReadInt32();
br.ReadByte();
if (revision != 1)
{
// for now, not storing this data
var width = br.ReadInt32();
var height = br.ReadInt32();
br.ReadInt32();
br.ReadInt32();
var string_ref = br.ReadInt32();
var string_length = br.ReadInt32();
var str = new string(br.ReadChars(string_length));
br.ReadSingle();
}
else
{
br.ReadInt32();
br.ReadInt32();
}
// read 9 fragments
obj.fragments = new List<fragment>();
for (var i = 0; i < 9; i++)
{
var frag = new fragment();
frag.width = br.ReadInt32();
frag.height = br.ReadInt32();
br.ReadInt32();
br.ReadInt32();
br.ReadInt32();
var tex_length = br.ReadInt32();
frag.texture = new string(br.ReadChars(tex_length));
br.ReadSingle();
br.ReadInt32();
frag.rect = new rect();
frag.rect.x1 = br.ReadInt32();
frag.rect.y1 = br.ReadInt32();
frag.rect.x2 = br.ReadInt32();
frag.rect.y2 = br.ReadInt32();
br.ReadInt32();
obj.fragments.Add(frag);
}
var last = br.ReadInt32();
if (obj.magic >= 3 && last == 0)
{
br.ReadInt32();
var string_length = br.ReadInt32();
var str = new string(br.ReadChars(string_length));
br.ReadBytes(42);
}
objects.Add(obj);
}
br.Close();
ms.Close();
}
}

Expand Down
2 changes: 1 addition & 1 deletion VBLauncher/EditorWindow.NonUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private void LoadFile(byte[] fb, string ext)
_currentFile = fb.ReadCRT();
break;
case ".int":
//_currentFile = INT.Parse(fb);
_currentFile = new INT(fb);
break;
case ".itm":
_currentFile = fb.ReadITM();
Expand Down
48 changes: 28 additions & 20 deletions VBLauncher/EditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public partial class EditorWindow
private readonly string[] _gwamDamageTypes = ["Ballistic", "Bio", "Electric", "EMP", "General", "Heat"];
private readonly string[] _triggerTypes = ["Building", "Script", "Transition"];

// ReSharper disable once InconsistentNaming - 2 is part of the abbreviation
// ReSharper disable once InconsistentNaming - 2 is part of the abbreviation
private int _2mwtChunk;
private CommandList _commandList;
private CommandList _commandList = null!;
private ImFontPtr? _consoleFont;
private dynamic _currentFile;
private dynamic _currentFile = null!;

private int _eeovSelected = -1;
private string _eeovTemp = "";
Expand Down Expand Up @@ -121,9 +121,9 @@ public partial class EditorWindow
private int _epthIndex;
private string[] _epthNames = [];
private int _epthPoint;
private string _extension;
private string _extension = null!;

private string _filename;
private string _filename = null!;
private ImFontPtr? _font;
private int _gcreEquipped;
private int _gcreSkill;
Expand All @@ -135,18 +135,18 @@ public partial class EditorWindow
private int _gcreTrait;

private int _gitmSocket;
private GraphicsDevice _graphicsDevice;
private GraphicsDevice _graphicsDevice = null!;
private int _gwamIndex;
private string[] _gwamNames = [];
private ImGuiRenderer _imguiRenderer;
private string[] _stf;
private ImGuiRenderer _imguiRenderer = null!;
private string[] _stf = null!;

private int _triggerIndex;
private string[] _triggerNames = [];
private int _triggerPoint;

private TextEditor _vegTextEditor;
private Sdl2Window _window;
private TextEditor _vegTextEditor = null!;
private Sdl2Window _window = null!;

public void Run()
{
Expand Down Expand Up @@ -347,7 +347,7 @@ private void ApplyAltUIColours()
style.FrameBorderSize = 1f;
}

private string GetColourCode()
private static string GetColourCode()
{
var sb = new StringBuilder();
sb.AppendLine("void embraceTheDarkness()");
Expand Down Expand Up @@ -389,7 +389,7 @@ private void DrawImGui()
if (ImGui.BeginMenu("New"))
{
var t = new[]
{ ".amo", ".arm", ".con", ".crt", ".dor", ".int", ".itm", ".map", ".use", ".veg", ".wea" };
{ ".amo", ".arm", ".con", ".crt", ".dor", ".itm", ".map", ".use", ".veg", ".wea" };
foreach (var s in t)
{
if (!ImGui.MenuItem(s)) continue;
Expand All @@ -401,7 +401,7 @@ private void DrawImGui()
".con" => new USE(USEType.CON),
".crt" => new CRT(),
".dor" => new USE(USEType.DOR),
//".int" => new INT(),
//".int" => new INT(), // TODO: how to handle new INT?
".itm" => new ITM(),
".map" => new Map(),
".use" => new USE(),
Expand Down Expand Up @@ -448,10 +448,10 @@ private void DrawImGui()
if (ImGui.MenuItem("Extract + Convert All .grp Files"))
ExtractAllGRPFiles(true);
if (ImGui.MenuItem("Show .grp Browser"))
using (var grpb = new GrpBrowser(null, true))
{
grpb.ShowDialog();
}
{
using var grpb = new GrpBrowser(null, true);
grpb.ShowDialog();
}

if (ImGui.MenuItem(".png to .rle"))
{
Expand Down Expand Up @@ -569,7 +569,7 @@ private void STFBox(string text, ref int sr)
ImGui.PopItemWidth();
}

private void HelpMarker(string desc)
private static void HelpMarker(string desc)
{
ImGui.TextDisabled("(?)");
if (!ImGui.IsItemHovered(ImGuiHoveredFlags.DelayShort)) return;
Expand Down Expand Up @@ -680,8 +680,16 @@ private void DrawVEG()
private void DrawINT()
{
ImGui.Begin("INT");
if (_currentFile.INT is not INT gui) return;
ImGui.PushItemWidth(-1);
if (_currentFile is not INT gui) return;
// create preview of the INT file
if (ImGui.Button("Preview"))
{
var ip = new IntViewer();
ip.Width = 1040;
ip.Height = 807;
ip.Show();
ip.LoadData(gui);
}
ImGui.End();
}

Expand Down
Loading

0 comments on commit a66639d

Please sign in to comment.