Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #17

Merged
merged 14 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Penumbra/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Dalamud.Configuration;
using Dalamud.Plugin;
using System;
using System.Collections.Generic;
using Dalamud.Configuration;
using Dalamud.Plugin;

namespace Penumbra
{
Expand All @@ -13,7 +13,7 @@ public class Configuration : IPluginConfiguration
public bool IsEnabled { get; set; } = true;

public bool ShowAdvanced { get; set; }

public bool DisableFileSystemNotifications { get; set; }

public bool EnableHttpApi { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Penumbra/Game/GameUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GameUtils
public UnloadPlayerResourcesPrototype UnloadPlayerResources { get; private set; }

// Object addresses
private IntPtr _playerResourceManagerAddress;
private readonly IntPtr _playerResourceManagerAddress;
public IntPtr PlayerResourceManagerPtr => Marshal.ReadIntPtr( _playerResourceManagerAddress );

public GameUtils( DalamudPluginInterface pluginInterface )
Expand Down
96 changes: 48 additions & 48 deletions Penumbra/Game/RefreshActors.cs
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
using System.Runtime.InteropServices;
using Dalamud.Game.ClientState.Actors;
using Dalamud.Game.ClientState.Actors.Types;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Dalamud.Game.ClientState.Actors;
using Dalamud.Game.ClientState.Actors.Types;

namespace Penumbra
{
public static class RefreshActors
{
private const int RenderModeOffset = 0x0104;
private const int RenderTaskPlayerDelay = 75;
private const int RenderTaskOtherDelay = 25;
private const int ModelInvisibilityFlag = 0b10;
private static async void Redraw(Actor actor)
{
var ptr = actor.Address;
var renderModePtr = ptr + RenderModeOffset;
var renderStatus = Marshal.ReadInt32(renderModePtr);
async void DrawObject(int delay)
{
Marshal.WriteInt32(renderModePtr, renderStatus | ModelInvisibilityFlag);
await Task.Delay(delay);
Marshal.WriteInt32(renderModePtr, renderStatus & ~ModelInvisibilityFlag);
}
if (actor.ObjectKind == Dalamud.Game.ClientState.Actors.ObjectKind.Player)
{
DrawObject(RenderTaskPlayerDelay);
await Task.Delay(RenderTaskPlayerDelay);
}
else
DrawObject(RenderTaskOtherDelay);
}
public static void RedrawSpecific(ActorTable actors, string name)
{
if (name?.Length == 0)
RedrawAll(actors);
foreach (var actor in actors)
if (actor.Name == name)
Redraw(actor);
}
public static void RedrawAll(ActorTable actors)
{
foreach (var actor in actors)
Redraw(actor);
}
public static class RefreshActors
{
private const int RenderModeOffset = 0x0104;
private const int RenderTaskPlayerDelay = 75;
private const int RenderTaskOtherDelay = 25;
private const int ModelInvisibilityFlag = 0b10;

private static async void Redraw(Actor actor)
{
var ptr = actor.Address;
var renderModePtr = ptr + RenderModeOffset;
var renderStatus = Marshal.ReadInt32(renderModePtr);

async void DrawObject(int delay)
{
Marshal.WriteInt32(renderModePtr, renderStatus | ModelInvisibilityFlag);
await Task.Delay(delay);
Marshal.WriteInt32(renderModePtr, renderStatus & ~ModelInvisibilityFlag);
}

if (actor.ObjectKind == Dalamud.Game.ClientState.Actors.ObjectKind.Player)
{
DrawObject(RenderTaskPlayerDelay);
await Task.Delay(RenderTaskPlayerDelay);
}
else
DrawObject(RenderTaskOtherDelay);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in editorconfig but always have braces


}

public static void RedrawSpecific(ActorTable actors, string name)
{
if (name?.Length == 0)
RedrawAll(actors);

foreach (var actor in actors)
if (actor.Name == name)
Redraw(actor);
}

public static void RedrawAll(ActorTable actors)
{
foreach (var actor in actors)
Redraw(actor);
}
}
}
79 changes: 44 additions & 35 deletions Penumbra/Importer/TexToolsImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class TexToolsImport

public ImporterState State { get; private set; }

public long TotalProgress { get; private set; }
public long TotalProgress { get; private set; } = 0;
public long CurrentProgress { get; private set; }

public float Progress
Expand Down Expand Up @@ -53,11 +53,8 @@ public void ImportModPack( FileInfo modPackFile )
switch( modPackFile.Extension )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why even really have this switch anymore if the version is used to check if its valid or not and what it is?

{
case ".ttmp":
ImportV1ModPack( modPackFile );
break;

case ".ttmp2":
ImportV2ModPack( modPackFile );
VerifyVersionAndImport(modPackFile);
break;

default:
Expand Down Expand Up @@ -88,15 +85,33 @@ private SqPackStream GetMagicSqPackDeleterStream( ZipFile file, string entryName
return new MagicTempFileStreamManagerAndDeleterFuckery( fs );
}

private void ImportV1ModPack( FileInfo modPackFile )
private void VerifyVersionAndImport(FileInfo modPackFile)
{
PluginLog.Log( " -> Importing V1 ModPack" );

using var zfs = modPackFile.OpenRead();
using var extractedModPack = new ZipFile( zfs );

var mpl = extractedModPack.GetEntry( "TTMPL.mpl" );
var modListRaw = GetStringFromZipEntry( extractedModPack, mpl, Encoding.UTF8 ).Split(
var modRaw = GetStringFromZipEntry( extractedModPack, mpl, Encoding.UTF8 );

// At least a better validation than going by the extension.
if (modRaw.Contains("\"TTMPVersion\":"))
{
if (modPackFile.Extension != ".ttmp2")
PluginLog.Warning($"File {modPackFile.FullName} seems to be a V2 TTMP, but has the wrong extension.");
ImportV2ModPack(modPackFile, extractedModPack, modRaw);
}
else
{
if (modPackFile.Extension != ".ttmp")
PluginLog.Warning($"File {modPackFile.FullName} seems to be a V1 TTMP, but has the wrong extension.");
ImportV1ModPack(modPackFile, extractedModPack, modRaw);
}
}

private void ImportV1ModPack( FileInfo modPackFile, ZipFile extractedModPack, string modRaw )
{
PluginLog.Log( " -> Importing V1 ModPack" );

var modListRaw = modRaw.Split(
new[] { "\r\n", "\r", "\n" },
StringSplitOptions.None
);
Expand Down Expand Up @@ -129,33 +144,26 @@ private void ImportV1ModPack( FileInfo modPackFile )
ExtractSimpleModList( newModFolder, modList, modData );
}

private void ImportV2ModPack( FileInfo modPackFile )
private void ImportV2ModPack( FileInfo modPackFile, ZipFile extractedModPack, string modRaw )
{
using var zfs = modPackFile.OpenRead();
using var extractedModPack = new ZipFile( zfs );

var mpl = extractedModPack.GetEntry( "TTMPL.mpl" );
var modList = JsonConvert.DeserializeObject< SimpleModPack >( GetStringFromZipEntry( extractedModPack, mpl, Encoding.UTF8 ) );
var modList = JsonConvert.DeserializeObject< SimpleModPack >( modRaw );

if( modList.TTMPVersion.EndsWith( "s" ) )
{
ImportSimpleV2ModPack( extractedModPack );
ImportSimpleV2ModPack( extractedModPack, modList );
return;
}

if( modList.TTMPVersion.EndsWith( "w" ) )
{
ImportExtendedV2ModPack( extractedModPack );
ImportExtendedV2ModPack( extractedModPack, modRaw );
}
}

private void ImportSimpleV2ModPack( ZipFile extractedModPack )
private void ImportSimpleV2ModPack( ZipFile extractedModPack, SimpleModPack modList )
{
PluginLog.Log( " -> Importing Simple V2 ModPack" );

var mpl = extractedModPack.GetEntry( "TTMPL.mpl" );
var modList = JsonConvert.DeserializeObject< SimpleModPack >( GetStringFromZipEntry( extractedModPack, mpl, Encoding.UTF8 ) );

// Create a new ModMeta from the TTMP modlist info
var modMeta = new ModMeta
{
Expand All @@ -179,12 +187,11 @@ private void ImportSimpleV2ModPack( ZipFile extractedModPack )
ExtractSimpleModList( newModFolder, modList.SimpleModsList, modData );
}

private void ImportExtendedV2ModPack( ZipFile extractedModPack )
private void ImportExtendedV2ModPack( ZipFile extractedModPack, string modRaw )
{
PluginLog.Log( " -> Importing Extended V2 ModPack" );

var mpl = extractedModPack.GetEntry( "TTMPL.mpl" );
var modList = JsonConvert.DeserializeObject< ExtendedModPack >( GetStringFromZipEntry( extractedModPack, mpl, Encoding.UTF8 ) );
var modList = JsonConvert.DeserializeObject< ExtendedModPack >( modRaw );

// Create a new ModMeta from the TTMP modlist info
var modMeta = new ModMeta
Expand All @@ -202,7 +209,7 @@ private void ImportExtendedV2ModPack( ZipFile extractedModPack )

var newModFolder = new DirectoryInfo(
Path.Combine( _outDirectory.FullName,
Path.GetFileNameWithoutExtension( modList.Name )
Path.GetFileNameWithoutExtension( modList.Name ).ReplaceInvalidPathSymbols()
)
);
newModFolder.Create();
Expand All @@ -216,10 +223,12 @@ private void ImportExtendedV2ModPack( ZipFile extractedModPack )
// Iterate through all pages
foreach( var page in modList.ModPackPages)
{
foreach(var group in page.ModGroups) {
var groupFolder = new DirectoryInfo(Path.Combine(newModFolder.FullName, group.GroupName));
foreach(var option in group.OptionList) {
var optionFolder = new DirectoryInfo( Path.Combine( groupFolder.FullName, option.Name ) );
foreach(var group in page.ModGroups)
{
var groupFolder = new DirectoryInfo(Path.Combine(newModFolder.FullName, group.GroupName.ReplaceInvalidPathSymbols()));
foreach(var option in group.OptionList)
{
var optionFolder = new DirectoryInfo( Path.Combine( groupFolder.FullName, option.Name.ReplaceInvalidPathSymbols()) );
ExtractSimpleModList( optionFolder, option.ModsJsons, modData );
}
AddMeta(newModFolder, groupFolder, group, modMeta);
Expand All @@ -240,18 +249,18 @@ private void AddMeta( DirectoryInfo baseFolder, DirectoryInfo groupFolder,ModGro
GroupName = group.GroupName,
Options = new List<Option>(),
};
foreach( var opt in group.OptionList )
foreach( var opt in group.OptionList )
{
var optio = new Option
{
OptionName = opt.Name,
OptionDesc = String.IsNullOrEmpty(opt.Description) ? "" : opt.Description,
OptionFiles = new Dictionary<string, HashSet<string>>()
};
var optDir = new DirectoryInfo(Path.Combine( groupFolder.FullName, opt.Name));
var optDir = new DirectoryInfo(Path.Combine( groupFolder.FullName, opt.Name.ReplaceInvalidPathSymbols()));
if (optDir.Exists)
{
foreach ( var file in optDir.EnumerateFiles("*.*", SearchOption.AllDirectories) )
foreach ( var file in optDir.EnumerateFiles("*.*", SearchOption.AllDirectories) )
{
optio.AddFile(file.FullName.Substring(baseFolder.FullName.Length).TrimStart('\\'), file.FullName.Substring(optDir.FullName.Length).TrimStart('\\').Replace('\\','/'));
}
Expand All @@ -273,7 +282,7 @@ private void ExtractSimpleModList( DirectoryInfo outDirectory, IEnumerable< Simp
// haha allocation go brr
var wtf = mods.ToList();

TotalProgress = wtf.LongCount();
TotalProgress += wtf.LongCount();

// Extract each SimpleMod into the new mod folder
foreach( var simpleMod in wtf )
Expand Down Expand Up @@ -307,7 +316,7 @@ private void ExtractMod( DirectoryInfo outDirectory, SimpleMod mod, SqPackStream
}
catch( Exception ex )
{
PluginLog.LogError( ex, "Could not export mod." );
PluginLog.LogError( ex, "Could not extract mod." );
}
}

Expand Down
Loading