Core Dream
Core Dream
CC#
Created by Core Dream on 10/28/2024 in #help
ListBox entries from UserControl not working.
public static class Logger
{
public static string WriteLog(string message)
{
return $"{DateTime.Now}: {message}";
}

public static void WriteLog(string message, LoggingUserControl loggingUserControl)
{
loggingUserControl.LogMessage(message);
}
}
public static class Logger
{
public static string WriteLog(string message)
{
return $"{DateTime.Now}: {message}";
}

public static void WriteLog(string message, LoggingUserControl loggingUserControl)
{
loggingUserControl.LogMessage(message);
}
}
public partial class LoggingUserControl : UserControl
{
private ListBox _loggingListBox;

public LoggingUserControl()
{
InitializeComponent();
_loggingListBox = LoggingListBox;
}

public void LogMessage(string message)
{
string formattedMessage = Logger.WriteLog(message);
_loggingListBox.Items.Add(formattedMessage);
}
}
public partial class LoggingUserControl : UserControl
{
private ListBox _loggingListBox;

public LoggingUserControl()
{
InitializeComponent();
_loggingListBox = LoggingListBox;
}

public void LogMessage(string message)
{
string formattedMessage = Logger.WriteLog(message);
_loggingListBox.Items.Add(formattedMessage);
}
}
private void GenerateHash()
{
if (HashInputTextBox.Text.Length > 0)
{
HashBytesOutputTextBox.Text = FNV1A.ByteArrayToString(FNV1A.HashToBytes(HashInputTextBox.Text.ToLower()));
Logger.WriteLog("Hash generated!",);
}
else
{
MessageBox.Show("Input is required!", "No Entry", MessageBoxButtons.OK);
}
}
private void GenerateHash()
{
if (HashInputTextBox.Text.Length > 0)
{
HashBytesOutputTextBox.Text = FNV1A.ByteArrayToString(FNV1A.HashToBytes(HashInputTextBox.Text.ToLower()));
Logger.WriteLog("Hash generated!",);
}
else
{
MessageBox.Show("Input is required!", "No Entry", MessageBoxButtons.OK);
}
}
193 replies
CC#
Created by Core Dream on 10/26/2024 in #help
WPF Resource Issue
No description
3 replies
CC#
Created by Core Dream on 9/20/2024 in #help
C# Normal Map file a .tiff or .dds
I am trying to create a normal map to save to a file and I am getting a ton of crap results from google, codeium, phind, co-pilot, etc. I tried OpenCv2Sharp, SharpDX.Direct3D11 etc I am not a math person nor raw graphics so I will need some hand holding. Can someone help? Thank you.
1 replies
CC#
Created by Core Dream on 9/7/2024 in #help
JSON Deserialization Multiple Entries
Hello. Is there an easy way to enumerate through this .json and pull out the data I need onto a UI? Stuff like Prop ID, Prop Name, etc. Of courses there's multiple props per .json so I'd need to be able to deserialize them all, edit them, and reserialize back.
{
"data": [
{
"prop_name": "Invalid",
"unk_14": 3728923965
},
{
"prop_id": 3,
"prop_name": "Ringbell",
"state": 1,
"mdl_path": 7636114012738718880,
"mtls_path": 5207710352904117017,
"prop_config_jsfb_path": 17346466537390459746,
"textures_path": 983795090616222792,
"unk_14": 3440520905
},
{
"prop_id": 4,
"type": 3,
"prop_name": "Dent_able_Chair_Black",
"state": 1,
"mdl_path": 11920831628306830712,
"mtls_path": 2176307239327909185,
"prop_config_jsfb_path": 18365218056640542593,
"textures_path": 1591327919772567142,
"havok_path": 17825444133106620151,
"sdb_name_id": 3419942826,
"render_path_1": 14812650683656359252,
"render_path_2": 3410622199164832471,
"unk_14": 433605154
},
{
"prop_id": 5,
"type": 1,
"prop_name": "table",
"state": 1,
"mdl_path": 3544448472792293094,
"mtls_path": 9384549906439149407,
"prop_config_jsfb_path": 18081587626750211327,
"ycl_path": 16030772999323866325,
"textures_path": 7145355447320130403,
"havok_path": 14679784151747246516,
"sdb_name_id": 968076457,
"render_path_1": 6628166879056395409,
"render_path_2": 7014051501087692342,
"unk_14": 3954428193
}
]
}
{
"data": [
{
"prop_name": "Invalid",
"unk_14": 3728923965
},
{
"prop_id": 3,
"prop_name": "Ringbell",
"state": 1,
"mdl_path": 7636114012738718880,
"mtls_path": 5207710352904117017,
"prop_config_jsfb_path": 17346466537390459746,
"textures_path": 983795090616222792,
"unk_14": 3440520905
},
{
"prop_id": 4,
"type": 3,
"prop_name": "Dent_able_Chair_Black",
"state": 1,
"mdl_path": 11920831628306830712,
"mtls_path": 2176307239327909185,
"prop_config_jsfb_path": 18365218056640542593,
"textures_path": 1591327919772567142,
"havok_path": 17825444133106620151,
"sdb_name_id": 3419942826,
"render_path_1": 14812650683656359252,
"render_path_2": 3410622199164832471,
"unk_14": 433605154
},
{
"prop_id": 5,
"type": 1,
"prop_name": "table",
"state": 1,
"mdl_path": 3544448472792293094,
"mtls_path": 9384549906439149407,
"prop_config_jsfb_path": 18081587626750211327,
"ycl_path": 16030772999323866325,
"textures_path": 7145355447320130403,
"havok_path": 14679784151747246516,
"sdb_name_id": 968076457,
"render_path_1": 6628166879056395409,
"render_path_2": 7014051501087692342,
"unk_14": 3954428193
}
]
}
(WinForms but it dont matter)
56 replies
CC#
Created by Core Dream on 9/1/2024 in #help
JSON Parsing to TreeView
Hello. I'm still banging my head on my desk the past 2 days trying to read a .json file which has a "table" root, into a TreeView. You'd think it would be easy for a dumbass but nope. Please help 😦 I tried ChatGPT, I tried Google, MS Learn, etc and I am a loser somehow. The example CharacterMapping.json file:
{
"table": [
{
"id": 100,
"character_path": 9155864901130912278,
"attire_path": 5838515536658117378,
"basemodel_mdl_path": 9608790949800725399,
"basemodel_mtls_path": 16869767090390095004,
"attire_mdl_path": 5619533544245612033,
"attire_mtls_path": 3740595121255541638,
"unk2": 30
},
{
"id": 101,
"character_path": 12279268510363823451,
"attire_path": 16519486993216130268,
"basemodel_mdl_path": 5133769854344942046,
"basemodel_mtls_path": 8091982216995671175,
"attire_mdl_path": 14803390407684558538,
"attire_mtls_path": 239947156153590923,
"unk2": 28
},
{
"id": 101,
"attire_num": 1,
"character_path": 12279268510363823451,
"attire_path": 15744211445203291278,
"basemodel_mdl_path": 5133769854344942046,
"basemodel_mtls_path": 8091982216995671175,
"attire_mdl_path": 8186642687843084600,
"attire_mtls_path": 9716164581340245505,
"unk2": 28
}
]
}
{
"table": [
{
"id": 100,
"character_path": 9155864901130912278,
"attire_path": 5838515536658117378,
"basemodel_mdl_path": 9608790949800725399,
"basemodel_mtls_path": 16869767090390095004,
"attire_mdl_path": 5619533544245612033,
"attire_mtls_path": 3740595121255541638,
"unk2": 30
},
{
"id": 101,
"character_path": 12279268510363823451,
"attire_path": 16519486993216130268,
"basemodel_mdl_path": 5133769854344942046,
"basemodel_mtls_path": 8091982216995671175,
"attire_mdl_path": 14803390407684558538,
"attire_mtls_path": 239947156153590923,
"unk2": 28
},
{
"id": 101,
"attire_num": 1,
"character_path": 12279268510363823451,
"attire_path": 15744211445203291278,
"basemodel_mdl_path": 5133769854344942046,
"basemodel_mtls_path": 8091982216995671175,
"attire_mdl_path": 8186642687843084600,
"attire_mtls_path": 9716164581340245505,
"unk2": 28
}
]
}
The source is here (FUCK GITHUB it keeps breaking)
52 replies
CC#
Created by Core Dream on 6/18/2024 in #help
Dependency Injection + MVVM?
I followed a Tim Corey tutorial on Dependency Injection in WPF but he did not use MVVM just raw code behind. How hard would be to switch over to MVVM? I just want an app where I have a MainView, SettingsView, and a few other Views. He uses Interfaces, etc and I'm lost. :< What should I do?
431 replies
CC#
Created by Core Dream on 5/4/2024 in #help
BindModel with DateTimePicker
I have a simple WinForms Dapper ORM w/SQLite app I've written, everything works except binding to the DateTimePicker controls. My model:
namespace TaskMinder.Model;

public class Entry
{
public int Id { get; set; } = 0;
public DateTime EntryDate { get; set; }
public DateTime EntryTime { get; set; }
public string EntryData { get; set; } = string.Empty;
}
namespace TaskMinder.Model;

public class Entry
{
public int Id { get; set; } = 0;
public DateTime EntryDate { get; set; }
public DateTime EntryTime { get; set; }
public string EntryData { get; set; } = string.Empty;
}
My method:
private void BindModel(Entry model)
{
NewEntryDatePicker.DataBindings.Add("Value", model, "EntryDate", true, DataSourceUpdateMode.OnPropertyChanged);
NewEntryTimePicker.DataBindings.Add("Value", model, "EntryTime", true, DataSourceUpdateMode.OnPropertyChanged);
NewEntryTextBox.DataBindings.Add("Text", model, "EntryData", true, DataSourceUpdateMode.OnPropertyChanged);
}
private void BindModel(Entry model)
{
NewEntryDatePicker.DataBindings.Add("Value", model, "EntryDate", true, DataSourceUpdateMode.OnPropertyChanged);
NewEntryTimePicker.DataBindings.Add("Value", model, "EntryTime", true, DataSourceUpdateMode.OnPropertyChanged);
NewEntryTextBox.DataBindings.Add("Text", model, "EntryData", true, DataSourceUpdateMode.OnPropertyChanged);
}
What am I doing wrong? Thank you in advance.
3 replies
CC#
Created by Core Dream on 1/29/2024 in #help
_sdbModel Model not being referenced
I am trying to enumerate my model and insert it into my SQLite database, but when I try, the model is null. Doing a debug on the ImportFileSDB() does show data in the model before the next method is called. Did I miss a step somewhere? I appreciate your advice. Main Form Class
using System.Diagnostics;
using TitanSTUDIO.Helpers.Parsers;
using TitanSTUDIO.Models;
using TitanSTUDIO.Repositories;

namespace TitanSTUDIO.Presentation
{
public partial class FTUEView : Form
{
static StringDatabaseModel? _sdbModel;

public FTUEView()
{
InitializeComponent();
}

private static async Task ImportSDBFile()
{
try
{
using (var ofd = new OpenFileDialog())
{
ofd.Filter = "String Database File (*.sdb)|*.sdb";
ofd.RestoreDirectory = true;

if (ofd.ShowDialog() == DialogResult.OK)
{
Debug.WriteLine("Reading SDB File...");

_sdbModel = await StringDatabase.ReadStringAsync(ofd.FileName);

// Import model data into the sqlite table.
await StringFileRepository.ImportData("StringsEnglishTable", StringFileRepository._sdbModel);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private async void NextStepBtn_Click(object sender, EventArgs e)
{
await ImportSDBFile();
}

private async void ImportSDB_Click(object sender, EventArgs e)
{
await ImportSDBFile();
}
}
}
using System.Diagnostics;
using TitanSTUDIO.Helpers.Parsers;
using TitanSTUDIO.Models;
using TitanSTUDIO.Repositories;

namespace TitanSTUDIO.Presentation
{
public partial class FTUEView : Form
{
static StringDatabaseModel? _sdbModel;

public FTUEView()
{
InitializeComponent();
}

private static async Task ImportSDBFile()
{
try
{
using (var ofd = new OpenFileDialog())
{
ofd.Filter = "String Database File (*.sdb)|*.sdb";
ofd.RestoreDirectory = true;

if (ofd.ShowDialog() == DialogResult.OK)
{
Debug.WriteLine("Reading SDB File...");

_sdbModel = await StringDatabase.ReadStringAsync(ofd.FileName);

// Import model data into the sqlite table.
await StringFileRepository.ImportData("StringsEnglishTable", StringFileRepository._sdbModel);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private async void NextStepBtn_Click(object sender, EventArgs e)
{
await ImportSDBFile();
}

private async void ImportSDB_Click(object sender, EventArgs e)
{
await ImportSDBFile();
}
}
}
Repository class: https://paste.mod.gg/tqxazwksrppy/0
2 replies
CC#
Created by Core Dream on 1/6/2024 in #help
Exporting all model data to a CSV
Hello. I have successfully pulled data out of a custom .sdb (not sqlite), from a old game and was trying to save it to a .CSV so I can import it into a database later (SQLite). I can do the last part just fine but getting a bit lost on the Export side. Thank you in advance.
5 replies
CC#
Created by Core Dream on 11/7/2023 in #help
❔ WF to WPF Help Needed
Hello sharpers. I have a issue where I need to convert at least the LoadFileSyncs to work with CommunityToolkit.MVVM in WPF I know how to Bind a ICommand to a button, I know how to do very basic ViewModel stuff so far but this is very new to me. OG Code is @ https://pastebin.com/EQyMRsvf My VM is @ https://pastebin.com/7cxT0ntv I appreciate you all!
8 replies
CC#
Created by Core Dream on 9/27/2023 in #help
❔ Bytes to UInt64
I am having a issue trying to turn the hex output to ulong, (UINT64). I keep getting 6687895829614943646 from 5CD02DD2B303DD9E I know 5CD02DD2B303DD9E should be 11447309898705915996 since my hex editor is right. I am using Little Endian. Any help would be appreciated, thank you. Here is my code:
private void GenerateHash()
{
// Make sure the input is not empty.
if (HashInput.Text.Length > 0)
{
// Convert \ to /
string hashInput = HashInput.Text.Replace(@"\", "/");
HashInput.Text = hashInput;

string hashString;
if (HashTypeList.SelectedIndex == 0)
{
hashString = ByteConverter.ByteArrayToString(HashFNV1.Hash(hashInput));
}
else
{
hashString = ByteConverter.ByteArrayToString(HashFNV1A.Hash(hashInput));

}

if (OutputAsHex.Checked)
{
HashResult.Text = hashString;
}
else
{
try
{

// Convert to UInt64
byte[] byteArray = HashFNV1A.Hash(hashInput);

if (BitConverter.IsLittleEndian)
Array.Reverse(byteArray);

ulong ulongValue = Convert.ToUInt64(hashString, 16);
HashResult.Text = ulongValue.ToString();
}
catch (OverflowException)
{
Console.WriteLine("Unable to convert '{0}' to an unsigned long integer.", hashString);
}
catch (FormatException)
{
Console.WriteLine("'{0}' is not in the correct format.", hashString);
}
}
}
}
private void GenerateHash()
{
// Make sure the input is not empty.
if (HashInput.Text.Length > 0)
{
// Convert \ to /
string hashInput = HashInput.Text.Replace(@"\", "/");
HashInput.Text = hashInput;

string hashString;
if (HashTypeList.SelectedIndex == 0)
{
hashString = ByteConverter.ByteArrayToString(HashFNV1.Hash(hashInput));
}
else
{
hashString = ByteConverter.ByteArrayToString(HashFNV1A.Hash(hashInput));

}

if (OutputAsHex.Checked)
{
HashResult.Text = hashString;
}
else
{
try
{

// Convert to UInt64
byte[] byteArray = HashFNV1A.Hash(hashInput);

if (BitConverter.IsLittleEndian)
Array.Reverse(byteArray);

ulong ulongValue = Convert.ToUInt64(hashString, 16);
HashResult.Text = ulongValue.ToString();
}
catch (OverflowException)
{
Console.WriteLine("Unable to convert '{0}' to an unsigned long integer.", hashString);
}
catch (FormatException)
{
Console.WriteLine("'{0}' is not in the correct format.", hashString);
}
}
}
}
67 replies
CC#
Created by Core Dream on 8/17/2023 in #help
❔ Async Method with current code.
I am having a hell of a brain fart, probably my damn ASD again. Can someone help me fix this?
private static string GetFilePath(StringBuilder builder, TrackViewModel track, string downloadPath, FileFormat fileFormat)
{
// Change ReleaseDate format to yyyy-MM-dd (Added by Core Dream Studios)

DateTime formattedDate = track.ReleaseDate;
var formattedDateString = formattedDate.ToString("yyyy-MM-dd");

builder.Clear();
builder.Append(formattedDateString);
builder.Append(" - ");
builder.Append(track.ArtistsTitle);
builder.Append(" - ");
builder.Append(track.Title);

if (!string.IsNullOrWhiteSpace(track.Version))
{
builder.Append('(');
builder.Append(track.Version);
builder.Append(')');
}

builder.Append(GetFileExtension(fileFormat));

var fileName = builder.ToString().SanitizeAsFileName();

var archivedFolderPath = $@"{downloadPath}\{formattedDateString} - {track.CatalogId} - {track.Title}";

// Create a subfolder inside the users download path based on the year, catalog id then the artist.
if (!Directory.Exists(archivedFolderPath))
Directory.CreateDirectory(archivedFolderPath);

// Added a ability to download coverart.
// Credit to @mtreit (https://github.com/treit)
// Credit to @angius (https://github.com/Atulin)


var cover = $"https://cdx.monstercat.com/?width={3000}&encoding=jpg&url=https://www.monstercat.com/release/{track.CatalogId}/cover";
DownloadCoverArtAsync(cover, archivedFolderPath);

return Path.Combine(archivedFolderPath, fileName!);
}

private static async Task DownloadCoverArtAsync(string coverURL, string downloadPath)
{
var _client = new HttpClient();
using var stream = await _client.GetStreamAsync(coverURL);
using var fs = new FileStream($@"{downloadPath}\cover.jpg", FileMode.Create);

stream.CopyTo(fs);
}
private static string GetFilePath(StringBuilder builder, TrackViewModel track, string downloadPath, FileFormat fileFormat)
{
// Change ReleaseDate format to yyyy-MM-dd (Added by Core Dream Studios)

DateTime formattedDate = track.ReleaseDate;
var formattedDateString = formattedDate.ToString("yyyy-MM-dd");

builder.Clear();
builder.Append(formattedDateString);
builder.Append(" - ");
builder.Append(track.ArtistsTitle);
builder.Append(" - ");
builder.Append(track.Title);

if (!string.IsNullOrWhiteSpace(track.Version))
{
builder.Append('(');
builder.Append(track.Version);
builder.Append(')');
}

builder.Append(GetFileExtension(fileFormat));

var fileName = builder.ToString().SanitizeAsFileName();

var archivedFolderPath = $@"{downloadPath}\{formattedDateString} - {track.CatalogId} - {track.Title}";

// Create a subfolder inside the users download path based on the year, catalog id then the artist.
if (!Directory.Exists(archivedFolderPath))
Directory.CreateDirectory(archivedFolderPath);

// Added a ability to download coverart.
// Credit to @mtreit (https://github.com/treit)
// Credit to @angius (https://github.com/Atulin)


var cover = $"https://cdx.monstercat.com/?width={3000}&encoding=jpg&url=https://www.monstercat.com/release/{track.CatalogId}/cover";
DownloadCoverArtAsync(cover, archivedFolderPath);

return Path.Combine(archivedFolderPath, fileName!);
}

private static async Task DownloadCoverArtAsync(string coverURL, string downloadPath)
{
var _client = new HttpClient();
using var stream = await _client.GetStreamAsync(coverURL);
using var fs = new FileStream($@"{downloadPath}\cover.jpg", FileMode.Create);

stream.CopyTo(fs);
}
Thanks
94 replies
CC#
Created by Core Dream on 7/18/2023 in #help
❔ ✅ ListView Annoyances.
I am trying to use await/async to pull all files from all folders in a chosen path. The issue I have is when trying to add them to a listview, and it keeps erroring out with the message: :'Cannot add or insert the item 'bakedfile00/AI/AIGOSGameObject.jsfb' in more than one place. You must first remove it from its current location or clone it. (Parameter 'item')' I am close to solving it, been trying various things but no luck. Can anyone help me? Thank you. My code is at this URL due to Discord message limit. https://pastebin.com/Eab8dP9F Thank you! ❤️
141 replies
CC#
Created by Core Dream on 4/6/2023 in #help
❔ VB to C# for Moving all folders and files?
Is there a way to do this in C# without relying on Microsoft.VisualBasic.FileIO? Thank you.
Sub MoveAllItems(ByVal fromPath As String, ByVal toPath As String)
My.Computer.FileSystem.CopyDirectory(fromPath, toPath, True)
'Here we want to not recycle the files since the files are moved
My.Computer.FileSystem.DeleteDirectory(fromPath, FileIO.DeleteDirectoryOption.DeleteAllContents)
End Sub
Sub MoveAllItems(ByVal fromPath As String, ByVal toPath As String)
My.Computer.FileSystem.CopyDirectory(fromPath, toPath, True)
'Here we want to not recycle the files since the files are moved
My.Computer.FileSystem.DeleteDirectory(fromPath, FileIO.DeleteDirectoryOption.DeleteAllContents)
End Sub
4 replies
CC#
Created by Core Dream on 2/7/2023 in #help
❔ Enumerating Running Processes
I am missing something, besides brain cells but what should I be returning if I want a ComboBox to have the list of Windows processes?
internal class ProcessHelpers
{
public static List<string> RunningProcessList = new();

public static string GetRunningProcesses()
{
Process[] processes = Process.GetProcesses().Where(p => (long)p.MainWindowHandle != 0).ToArray();

foreach (Process process in processes)
{
RunningProcessList.Add(process.ProcessName);
}

return List<string> RunningProcessList;
}
}
internal class ProcessHelpers
{
public static List<string> RunningProcessList = new();

public static string GetRunningProcesses()
{
Process[] processes = Process.GetProcesses().Where(p => (long)p.MainWindowHandle != 0).ToArray();

foreach (Process process in processes)
{
RunningProcessList.Add(process.ProcessName);
}

return List<string> RunningProcessList;
}
}
140 replies
CC#
Created by Core Dream on 2/1/2023 in #help
❔ System.AccessViolationException: 'Attempted to read or write protected memory.
Even with <AllowUnsafeCodeBlocks> enabled and using unsafe { }, this error does not go away. And before anyone asks, no this is not a cheat app or related to online gaming. Is this a limitation of C#? Thanks! System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
41 replies
CC#
Created by Core Dream on 10/30/2022 in #help
Need Python to C Sharp Conversion
``` Summary: Trying to port a CRC32 lib Martin Scharrer created in Python, I see no known C# version and I am barely a Python dev. Sources: https://github.com/MartinScharrer/crccheck/blob/main/crccheck/crc.py https://github.com/MartinScharrer/crccheck/blob/main/crccheck/checksum.py I do have the crc.py, I will add it to this post if anyone can give me a clue. I appreciate you so much and yes I'd include his license and credit. 🙂
39 replies
CC#
Created by Core Dream on 8/19/2022 in #help
BinaryReader Question
Trying to read the values AS bytes, but reader reads them as decimals, is there a trick to making it bytes?
private void ReadArenaDefs(string arenaSlotNumber)
{
string fileName = @$"{AppDomain.CurrentDomain.BaseDirectory}\ArenaDefinition_00505.jsfb";

byte[] bytesCrowdType = new byte[8];
int offset = 288;

if (File.Exists(fileName))
{
using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open)))
{
reader.BaseStream.Seek(offset, SeekOrigin.Begin);
reader.Read(bytesCrowdType, 0, 8);
}
}
}
private void ReadArenaDefs(string arenaSlotNumber)
{
string fileName = @$"{AppDomain.CurrentDomain.BaseDirectory}\ArenaDefinition_00505.jsfb";

byte[] bytesCrowdType = new byte[8];
int offset = 288;

if (File.Exists(fileName))
{
using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open)))
{
reader.BaseStream.Seek(offset, SeekOrigin.Begin);
reader.Read(bytesCrowdType, 0, 8);
}
}
}
49 replies