|
Hello, I'm currently making a program that will take a HEX string and convert it into an image.
I talked to a experienced coder and he gave me some steps to my problem:
1) Create a simple hello world program with a main method
2) Make it so your program can print out the byte array you input to the console
3) Figure out how to link in the libraries the code you posted references (looks like SkiaSharp and PakReader)
4) Make the call to the code you showed (TextureDecoder.DecodeImage)
5) Write the resulting SKImage to a file
I'm trying to call a method from a separate program. I'm really inexperienced and confused even after looking at documentation and multiple YT videos.
I had a couple of questions about how I should do this:
I'm trying to call
TextureDecoder.DecodeImage
from the program in the link below.
hastebin[^]
MY current code so far, based off of the first 3 Steps a guy gave me for help:
using System;
using System.IO;
using PakReader.Parsers.Objects;
using SkiaSharp;
namespace EncyptedViewing
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("HEX Input");
}
}
}
I would like to know how I would call the class from the link above TextureDecoder.DecodeImage into the program above, or is that not possible and I need to do it all in one program?
Thanks, and stay safe.
|
|
|
|
|
Try
SKImage ski = PakReader.TextureDecoder.DecodeImage(sequence, width, height, depth, format); You'll have to work out what the parameter values contain for yourself: we have no idea what you are trying to do with it.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I entered code from a YouTube video into Microsofts version 8 compiler but can't get the cards to display. The code is written in 2017 for an older compiler.
In the code it has
Public override string ToString()
{
Return face + " of " + suit;
}
Would this code apply to the latest microsoft compiler?
The only code for printing the cards is
Console.write( deck1.DealCard());
Which is looped.
The problem is finding out why the cards are not displayed.
If needed I could give you the whole code but I can't remember how you format the code in this forum.
Cards should be printed as 4 of hearts etc.
Brian
|
|
|
|
|
The code applies to any version of C#. There's really nothing to it. All it's doing is returning a string with the value of face and suit converted to strings.
Those two variables have to be supplied by other code in your class.
There's no way to tell you what you're doing wrong since we can't see the code for the type deck1 is, nor can we see the code for what, I assume, your card class is.
You're going to have to hit the "Improve question" button to add the relevant code to your question.
Also, stay away from YouTube videos for learning to code. I haven't seen a good one yet.
|
|
|
|
|
Dave Kreskowiak wrote: stay away from YouTube videos for learning to code. I haven't seen a good one yet.
I suspect that most of 'em are created by people who
1) Have no idea how to make a good video
And
2) Have no idea how to code.
They have code that works, but they have no idea why it does - so they blindly type it in and then show "working" results - that most times are unrelated to the code they actually typed.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Yeah.
Every video I've seen doesn't go into anywhere enough detail as to why they are doing the things they are. I suspect this is because of just what you said. They have no idea what they're doing.
Just showing what may even be simplified code from a more complex topic is done without sufficient explanation.
|
|
|
|
|
Hi Griff.
Can you suggest somewhere that I might be able to find C# code listing for a card shuffing program or any card program.
Brian
|
|
|
|
|
<pre lang="c#">
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Card_Shuffle
{
public class Deck
{
private Card[] deck;
private int currentCard;
private const int NUMBER_OF_CARDS = 52;
private Random ranNum;
public Deck()
{
string[] faces = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nin", "Ten", "Jack", "Queen", "King" };
string[] suits = { "Hearts", "Clubs", "Diamonds", "Spades" };
deck = new Card[NUMBER_OF_CARDS];
currentCard = 0;
ranNum = new Random();
for (int count = 0; count < deck.Length; count++)
deck[count] = new Card(faces[count % 11],
suits[count / 13]);
}
public void Shuffle()
{
currentCard = 0;
for (int first = 0; first < deck.Length; first++)
{
int second = ranNum.Next(NUMBER_OF_CARDS);
Card temp = deck[first];
deck[first] = deck[second];
deck[second] = temp;
}
}
public Card DealCard()
{
if (currentCard < deck.Length)
return deck[currentCard++];
else return null;
}
public class Card
{
private string face;
private string suit;
public Card(string cardFace, string cardSuit)
{
face = cardFace;
suit = cardSuit;
}
public override string ToString()
{
return face + " of " + suit;
}
}
static void Main(string[] args)
{
Deck deck1 = new Deck();
deck1.Shuffle();
for (int i = 0; i < 52; i++)
{
Console.Write("0-19)", deck1.DealCard());
if ((i + 1) % 4 == 0)
Console.WriteLine();
}
Console.ReadLine();
}
}
}
</pre>
At the moment I get 13 rows of the below text displayed.
0-19)0-19)0-19)0-19)
Brian
|
|
|
|
|
Brian_TheLion wrote: At the moment I get 13 rows of the below text displayed. Quite right because that is what your code is doing. Look at the line:
Console.Write("0-19)", deck1.DealCard());
It says print the string "0-19)"; the second part deck1.DealCard() returns a string but does nothing with it. The rest of the code does very little of any use.
As already suggested you should stop wasting your time on YouTube and get hold of a decent book on C#.
|
|
|
|
|
Hi Richard.
Do you think there is some code missing?
If this is the case then I may have to give up on getting this code to work unless you could suggest some extra code I could add to the existing code.
Brian
|
|
|
|
|
Quite frankly I don't think it's the best design of a card class that I have seen. Also, nearly all the code we see here that is taken code from a Youtube video, turns out to be not very well written. Youtubers tend not to be particularly skilled coders. If you want to learn C# properly then get hold of a decent book on the subject, it will be time and money far better spent.
|
|
|
|
|
Brian_TheLion wrote:
Console.Write("0-19)", deck1.DealCard()); I suspect that should be:
Console.Write("{0,-19}", deck1.DealCard()); Composite formatting | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard.
Thanks fro the suggestion.
I did as you suggested by got an error of "Input string was not in correct format".
Brian
|
|
|
|
|
|
You were correct Richard.
When I tried the format code you offered I had left the comma out of the code and got an error
I tried
Console.Write("{0-19}", deck1.DealCard());
instead of
Console.Write("{0,-19}", deck1.DealCard());
All is working find now thanks.
Brian
|
|
|
|
|
Firstly, Return is not a C# keyword: it's case sensitive, remember - so it's return instead.
Secondly, what
return face + " of " + suit; returns depends on the type of face and suit - if they are both strings, it'll work. If face is an integer, it'll work. If it's a special class, then it'll only work if you have overridden ToString in that class.
But basically, we can't directly help you - we can't run your code in isolation and get the same results you do.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi Griff.
I did try stepping through the code but with the way the program is written I can't always get exact values for some of the variables.
I have sent the complete code in hope that you might spot an error.
I posted the complete code as a reply to my first reply which I think was from yourself.
Hoping you can help
Brian
|
|
|
|
|
Brian_TheLion wrote: I did try stepping through the code but with the way the program is written I can't always get exact values for some of the variables.
Cobblers.
If you can't get "exact values" with the debugger then you are using it wrong - or not using it at all - when you run code in the debugger it is executing your code, so you get to see exactly what you code does when it is running.
If the values you see are not what you expected, then that's a problem with your code, not with the debugger - and that's what the debugger is there for, to help you find the palces where your code isn;t doing what you expected it to.
Shuffling cards is trivial: a very simple way to do it is to put all the cards in an array and use an random number generator to give you two indexes: swap the two cards in those locations. Repeat that at least 5 or 6 times the number of cards involved (52 in a normal pack, so 260 to 312) and the cards are shufffled ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hi Griff.
I'll give you an example why I'm not getting enought info when debugging.
Please refer to my code that I posted a day ago .
In the line return deck[CurrentCard++], If I put on cursor on deck[CurrentCard++] up pops the message "deck1 Card_Shuffle.Deck)"
In the Console.Write line of code, if I put my cursor on deck1.DealCard() then up pops the message "deck1 Card_Shuffle.Deck).
I can't see how I can find out what is wrong by the messages I get when checking these variables in the code.
Brian
|
|
|
|
|
That's just the basic type info for what you're hovering over. When you hover over deck1 it shows the info for that object. If you want to know what "deck1[x]" is then you can highlight the whole string including the square brackets, right click and select "Quick Watch" from the context menu.
Another debugging tip is that compound statements like this
Console.Write("0-19)", deck1.DealCard());
are harder to debug. While still in the coding process it will often help to split things up into individual lines
Card card = deck1.DealCard();
Console.Write("0-19)", card);
You can now inspect "card" to see what DealCard has returned. If it looks like what you expect then you know it is the Console.Write that isn't doing what you expect. By splitting the code into two separate stages you can test them separately...you can test DealCard is doing what you want, then Console.Write. With your original code you are doing two things at once so it is harder to know which of those things is failing. Once you have your bugs ironed out and the code working, you can go back to the code in line if you wish.
The reason your Console.Write isn't working is because you are using the two param method, so the first param ("0-19)") is the "format" and the second param ("card") is the data you want to show in that format. However "0-19)" is not a proper formatting string so all you will get is that text out verbatim. A formatting string has placeholders for the values, so {0} for the first param, {1} for the second etc.
To see this in action try;
Card card = deck1.DealCard();
Console.Write("card {0} = {1} ", i, card);
|
|
|
|
|
Thanks F-ES Sitecore for the suggested changes to the code.
I finally have got this program to print out the cards. Good to make some progress.
I altered the your code to
Console.Write(card+",");
so they would print in my preferred format.
Brian
|
|
|
|
|
Hi F-ES Sitecore.
I had another look at the original and found that I had made a mistake.
Console.Write("0-19)", deck1.DealCard);
should have been
Console.Write("{0,-19}", deck1.DealCard);
I don't think a debugging the code would have lead me to the correct code but I can see your point in expanding the code over several lines.
Brian
|
|
|
|
|
Let's assume we have methods that calculates something:
public int calculateSomething1(int param)
{
int calculatedValue;
...Calculations...
return calculatedValue;
}
public int calculateSomething2(int param)
{
int calculatedValue;
...Calculations...
return calculatedValue;
}
What would be the best way to store these in a database (we can assume SQL Server)? Would it be to put the methods in separate dll:s and then insert all the bytes inside the dll into the database and then load them as dynamic dll:s in RAM? Or something else? Inserting the raw source code as varchar and then compile it in runtime is too slow.
|
|
|
|
|
What exactly are you trying to do? Code should go in your program not the database.
|
|
|
|
|
It's for register maps and register value loop-up for different products and it would be nice if only the database (not the .exe-file) needs to be updated as we add new products and registers. For example, let's assume a register called MONTH, this register would need this table to convert from an integer to a user-friendly string:
1 January
2 February
3 March
4 April
5 May
6 June
7 July
8 August
9 September
10 October
11 November
12 December
Now, let's a assume a different register called YEAR_MONTH_AND_DATE, all stored within the same integer, image how big that lookup table would be. Instead, it would be much easier to just a have method to do the conversion:
public string convertYearMonthAndDate(UInt32 yearMonthAndDate)
{
UInt16 year = (UInt16)(yearMonthAndDate >> 16);
byte month = (byte) (yearMonthAndDate >> 8);
byte date = (byte) (yearMonthAndDate >> 0);
string monthString = "";
switch (month)
{
case 1: monthString = "January"; break;
case 2: monthString = "February"; break;
case 3: monthString = "March"; break;
case 4: monthString = "April"; break;
case 5: monthString = "May"; break;
case 6: monthString = "June"; break;
case 7: monthString = "July"; break;
case 8: monthString = "August"; break;
case 9: monthString = "September"; break;
case 10: monthString = "October"; break;
case 11: monthString = "November"; break;
case 12: monthString = "December"; break;
}
return monthString + " " + date + ", " + year;
}
|
|
|
|