iBotPeaches Posted November 9, 2007 Report Posted November 9, 2007 Preyhttp://www.ibotmodz.net/forum/uploads/remoteimages1/2687-574.gif Well with having done VB for one year, C# fortwo, reading a 900 page book on C++ one and a half times, reading a 400page book on DirectX, writing several crappy games with DirectX,writing one game in GSE for the 360, and making about a millionapplications and only releasing about a tenth, I think it's time topass on some of the knowledge that I have gained. Understandablythere are people here with a lot more than 3 years experience, so feelfree to pull this apart if it is total **** in your eyes ;o> This isn't a full blown tutorial, but more of something you can lookback upon as a reference, it'll only be focusing on some core and somenot-so-core subjects but by keeping these things in mind, you've justmade your application about a hundred times better http://www.ibotmodz.net/forum/uploads/remoteimages1/2687-575.gif Anyway lets get to it shall we? Getting StartedThis is something that isn'tgoing to be explained here. About a million books and online tutorialsexist these days, more often then not made by top professionals who know exactly what they're talking about. So you should find most to be very useful indeed, I know I did. One thing I will note here though is that we will be primarily focusingon Microsofts C#, but many of the topics covered can pertain to VB andC++ also. C# can be downloaded from THIS page on their website. Alternatively you could buy Visual Studio 2005 from HERE on their website. VS comes with VB, C# and C++ as well as a few other pieces of software. The VisionThis is where it all starts, the idea. A short sentence or smallparagraph, it is what will drive you during the course of developmenton your new program, and is one of the most important parts of thedevelopment cycle. With the realization of this new idea comes a very importantchoice: either you decide to let it pass by and continue on with yourlife, or you decide to realize this idea and do everything in yourpower to do just that. Now let me quickly list 2 very important don'ts:[*]The program must simplify some sort of process. In the case ofHalo2, inserting a longer string into the unicode table means shiftinga lot of data, which manually means one hell'uva lot of work. But witha program doing all that work for you the process has just beendramatically simplified. Thus such a program is a good idea.[/*:m:2ddvq3bw][*]If your idea has already been realized in some sort of otherapplication, you should not continue unless you honestly feel that thejob could have been done better. In the case of a calculator, theres nopoint in making it if the eventual result is not going to be betterthan the one Windows comes with for free.[/*:m:2ddvq3bw]So assuming you took choice #2, and your idea is not a don't; it's time to move on to the next stage. PlanningTime to get out your pen and paper, or open up some sort of wordprocessor, and begin writing the basis of your application. What is itgoing to do? Look like? Who is it aimed at? How are the internalworkings going to be ordered? Don't ever just jump into it, that is a very foolhardy thing to do,and believe me I know as I've done it quite a few times myself. Withplanning comes good structure, which means a good, robust applicationat the end of it all. It also means then when you open the project backup a few months later, you can quickly get back up to speed with theinner workings and quickly progress on whatever update you wish toimplement. Once you've got down a basic plan for your application, the next step is to start teasing out the possible loopholes. ScenariosThings that may happen during runtime that you've got to look outfor. For example if the application resigned Halo2 maps; you may haveone button to open the map and one to resign the open map. But what ifthe user presses the resign button without first opening a map? Youhave two choices in this case:[*]Either have a boolean value indicating whether a map has beenopened or not. If one has not either do nothing or MessageBox the usertelling them what they have done wrong. or just be rude ;o[/*:m:2ddvq3bw][*]OR the resign buttonis disabled until a map has been opened, in which case it becomesenabled allowing for the map to be resigned.[/*:m:2ddvq3bw]Whilst the first option would work, it is also misleading. For someonewho has no idea what resign means, you have already managed to confusewith even the most basic of programs. But with only one button enabledon the form, it is obvious to anyone that first a file has to be openedto continue. With larger applications theres bound to be a lot more scenarios,but remember you only need to take note of the ones that do presentloopholes in your application. You should have also started going backto the model you created in the planning stages and noting down theprecautions that will have to be taken at certain points in yourprogram, to ensure that any loopholes you've found cannot be exploited. Moving OnI've covered the basis of planning here, as it's beyond the scopeof this 'tutorial' to go any further in-depth, but if you do feel theneed to, there are several books on offer pertaining to just those stages and that also delve into applying your plan to an object-oriented environment. Moving on to the actual creation, here are now a few points to keep in mind when making your application. UI - User Interface - What you SEEThink of it in stages, first everything is disabled apart from thebutton that opens the map. But once a map is opened the treeview comesto life displaying the tags of the map. On selecting one of them themeta editor comes to life with the properties of the selected tag.Simple, although this has left a bug in the application: What if theuser selects a tag class? (such as 'weap'), we know that a class is nota tag and thus doesn't contain any defining properties/meta. In thiscase you would instead disable the meta editor. Note that this is alsosomething you should have considered when thinking out possiblescenarios. Multiple windows are generally a bad idea, and you shoulddefinitely avoid having very many at all. Tabcontrols on the other handare better for when you need to display multiple pieces of informationabout something, but have limited space to work with. There is onething I should mention though about tabcontrols; their disabled state. http://www.ibotmodz.net/forum/uploads/remoteimages1/2687-576.png It looks crap. Please never disable a tabcontrol! A moreinteresting way of doing things is to actually remove the tabpages onstartup, and then add them back in when needed. Note that the followingcode is C#, but should be easily transferable to both VB and C++. Ifyou can't convert then google a converter; theres a lot of them aroundon the net these days. C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD] public partial class Form1 : Form { public Form1() { InitializeComponent(); tabControl1.TabPages.Clear(); } private void button1_Click(object sender, EventArgs e) { // Open the map here.. if (tabControl1.TabCount == 0) { tabControl1.TabPages.AddRange(new TabPage[] { tabPage1, tabPage2 }); } } }[/TD] [/TR][/TABLE]Code assumes TabControl is named tabControl1. And as you can see if you try it out, a much better effect is achieved. TextBoxesJust one small quiff with these, I have no idea why but for somereason the makers of the almighty textbox for VS2005, decided to notadd in the Ctrl + A shortcut. Which in my eyes is one of the bestshortcuts a textbox could have. Anyway, to implement it modify thePreviewKeyDown event of the textbox as follows: C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD] private void textBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.Control && e.KeyCode == Keys.A) textBox1.SelectAll(); }[/TD] [/TR][/TABLE]Code assumes TextBox is named textBox1. CommentingComments are the nice little green lines that explain whats goingon where, but sometimes it is possible to over do it quitespectacularly (again, something else i have fallen trap to). C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD] //declares 'num' to be an integer that is equal to 0 int num = 0; //increments 'num' by 5 num += 5;[/TD] [/TR][/TABLE] There is two things wrong with these comments. The first being theyrely on the code too heavily. You should never go that in-depth, as youcan see the first references the name of the variable and its initialvalue. Very bad practice. If either changes the comment also has tochange otherwise it won't make any sense. This is a pointless bother. The other problem with these comments is that they are not needed. Itseems as if you are trying to teach someone the language here, but inreality they are expected to already know it. What comments shouldactually be telling you is the why,there should also be a gap after the slashes for clarity, and thecomment itself should be written as a proper sentence/paragraph. C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD] int num = 0; // We increment the number as such to make // things a little more interesting. num += 5;[/TD] [/TR][/TABLE] Accessors C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD]public int num;[/TD] [/TR][/TABLE] Red light. C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD]private int num;public int Num { get { return num; } set { num = value; } }[/TD] [/TR][/TABLE] Green light. Accessors should always be uses because it allows you to separate the details of how the data is stored from how it is used.By using accessor functions, you can later change how the data isstored without having to rewrite any of the other functions in yourprogram that use the data. Although accessors are a pain to implement (we'll come back tothis..), they make your program so much easier to manage and maintain,plus add such a layer of professionalism that'd you'd by silly to notuse them =| I haven't exactly mentioned it yet, but the get and set do actuallyact as functions. There's no limit to how many instructions they canhold but as a general rule you want to keep it pretty small. As anexample we will make an accessor that stores the first four letters ofthe map, which we know to be 'deah': C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD]#region Instance Data private string __head__; #endregion #region Accessors ////// Head///public string Head { get { return __head__; } set { if (value.Length <= 4) __head__ = value; } } #endregion[/TD] [/TR][/TABLE] You see just a tiny instruction to make sure the new string is nobigger than four letters. Much easier to implement here, than in everymethod that gives 'Head' a value. Going back to they're a pain to implement (and you can't deny they aren't http://www.ibotmodz.net/forum/uploads/remoteimages1/2687-577.gif ), I have gone and laboured over, well, an application that will generate them for you http://www.ibotmodz.net/forum/uploads/remoteimages1/2687-578.gif http://www.ibotmodz.net/forum/uploads/remoteimages1/2687-579.png Click HERE to download. We will now quickly go over the screenshot:The first thing you may notice is the rather nice layout ( http://www.ibotmodz.net/forum/uploads/remoteimages1/2687-580.gif).. the 2nd is that two underscores have been added to each side of theprivate member. This is done with the built in macros in C++, so to notget in the way of any of your own custom names. I think it's a goodidea and not to over the top thus its implementation. SummariesThe next thing you may have noticed is that each accessor has it's ownsummary. By default the app will insert the name of the accessor, butfeel free to change that. Summaries are always useful for explainingproperties: http://www.ibotmodz.net/forum/uploads/remoteimages1/2687-581.png They can also be used to explain methods too: http://www.ibotmodz.net/forum/uploads/remoteimages1/2687-582.png ..and classes and structs..the list goes on and on... The BinaryReader and BinaryWriterThey're great classes, but there are a few things that may not be so obvious at first: 1. C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD] string str = "hello"; bw.Write(str);[/TD] [/TR][/TABLE]Code assumes BinaryWriter is named bw. This will not just write the string, but just before the string thelength of the string will actually be written as well. To avoid this,do the following instead: C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD] string str = "hello"; bw.Write(str.ToCharArray());[/TD] [/TR][/TABLE]Code assumes BinaryWriter is named bw. 2. C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD] char[] chars = br.ReadChars(4);[/TD] [/TR][/TABLE]Code assumes BinaryReader is named br. The ReadChars method has a tendency to trot off down the stream ifat the current position there is not a valid char. This usually resultsin unexpected, and unwanted results (one of them being the app crashingas the reader tries to continue past the stream). To avoid: C# [TABLE][TR] [TD]Code:[/TD] [/TR] [TR] [TD]char[] chars = Encoding.ASCII.GetChars(br.ReadBytes(4));[/TD] [/TR][/TABLE]Code assumes BinaryReader is named br. I have written 2 classes that expand upon the BinaryReader andBinaryWriter, that fix the above 'errors' and add more functionality,and have dubbed them BitReader and BitWriter. You can download them HERE. Enjoy =) Classes vs StructsI'm not going to go into it here, but I will point you to a place thatexplains it in detail. Again the code is C#, but can be applied to bothVB and C++ (the .nf2.0 or higher C++ that is). LINK SecurityWith visual studio your application is compiled into the Intermediatelanguage (IL). But the thing is it is very easy to reverse engineerthis language to get at the original source code, the applications thatdo this are known as decompilers. To battle them we have what is knownas obfusticators. These powerful applications take the source code andscramble it wherever possible, giving the lowlife that is trying toread your source code a real hard time at it. Buy Visual Studio and you'll get a pretty good obfusticator as anextra, but for those of us with the express editions the best freewareobfusticator I could find was HERE. Its a 'light' version of the proper one being sold on that website, but I have found it to be actually rather good. EndIf I think up anything else I'll be sure to add it in, or if you feelsomething's missing feel free to post and I'll look into it. You might wonder why I felt the need to write such a 'reference'. Theanswer to that, if I'm being honest, is because that many of theapplications posted here on halomods have lacked any 'professionalism'in my eyes, including my own, and so I thought by putting up areference that examined a few 'essential' points, we could stop withthe crap (don't take that personally) and move on to the good http://www.ibotmodz.net/forum/uploads/remoteimages1/2687-575.gif Enjoy,~Prey
Recommended Posts
Archived
This topic is now archived and is closed to further replies.