Category Archives: News

Blog Revamp — Starting over..

Hello everyone,

I have once again kind of neglected this blog and stopped posting in it although I have been busy coding on various projects. Bits and pieces of things I could have shared but haven’t seem to cross my mind a lot granted I know I’m no professional or anything when it comes to coding, I still enjoy helping others and sharing what I do know.

My blog was fairly random and unorganized before. I lacked using categories on a lot of posts, things were poorly written and rushed, and so on. Instead I’d rather this be a more professional looking thing than just a dump for misc chunks of code. With that, I am revamping the blog; within reason. I have removed all the old posts and will be reposting something of them that I feel suit the purpose of this site now. Along with that I will do what I can to post a bit more frequently about what I am doing or sharing more things.

No promises on things as usual, I’m sure my schedule is going to flip around again soon so we’ll see how things go from here. 🙂


About Me page has been updated!
Projects and Links page has been updated!

~ atom0s

.NET Header Reader

Wrote this for someone on Tuts4You the other day to show how to read the flags field from the IMAGE_COR20_HEADER section of a PE file header. It’s fairly plain and has little error checking. If it throws an exception it will crash since it was just a basic ‘how-to’ type thing.

Credits are in the HeaderHelper.cs class since that contains the main jist of things.

Download:
DotNetFileReader

Update

I really need to get back into updating this more often..

Backend Update..
Updated the blog again to the latest version of WordPress. This time being 3.0, although it looks exactly the same. Yay I guess. Nothing really much changed, just some random updates and fixes for the software. Still, the best blogging software on the net.

patchLib v3?
So I’ve been working on a side project that involves some things that patchLib does. (Rendering a Gui via GDI / UpdateLayeredWindow.) This turned into a bug fix experience. By this I mean I found the reason to a few bugs in patchLib v2, as well as finally figured out how to fully draw Win32 controls ontop of a layered window. Sadly there are still some issues that I can’t fully figure out yet, but I am working on it slowly and when I’m bored. But I am unsure if this will spark me to write patchLib v3, so we’ll see.

Garrys Mod
I got into Garrys Mod for a while, mainly because of the Lua programming. For those that don’t know, Garrys Mod is entirely ran using Lua. While the main core of the game is done using the Orange Box engine from Valve, the game is powered by Lua in the end. All the events and such are done based on Lua scripts and so on. In my opinion, GMod is the best example of how powerful Lua can be as an embedded language in an application.

I mainly got into GMod because of a few friends playing a private gamemode. I got my hands on this gamemode and started my own server for a few months. It never really exploded with popularity but we did have some regulars which was fun for the time being. Overall I spent majority of my time not playing but fixing bugs in the Lua scripts from the original author. Which really got me interested in Lua again.

Two major things in GMod that really got me into Lua again was their implementation of timers and hooks. My first time around with Lua I tried to get something similar working but failed. However this time around I’ve finally figured it out. Granted I have no idea if I’m doing it “correctly” or the same as GMod but I did get my timer and hook modules working. They are based on GMods scripts, but his scripts are based on old Lua stuff that’s been done before as well.

I’ve also modded my Lua install to include bitwise operations and logical operators. (Using a community patch, and with the help of a Lua forum user.) Which allows users to use things such as:
!, !=, &&, ||, &, |, ^^, <>, ~,

For testing my Lua stuff I use the following script:

–[[

Lua Demonstration Script
(c) 2010 atom0s

This script is used to test a personal installation
and modification of Lua. This script will not work
on stock Lua installs!

]]–

print( string.format( &quot;test.lua – Script started at: %d&quot;, os.time() ) );

— Require hooking package.
require( ‘hook’ );
local hook = hook;

— Require timer package.
require( ‘timer’ );
local timer = timer;

— Logical operation tests.
local bTest1 = false;
local nTest2 = 1234;
local nTest3 = 4321;

print( string.format(
&quot;Logical test #1: %snLogical test #2: %snLogical test #3: %s&quot;,
tostring( !bTest1 &amp;&amp; bTest1 != true ),
tostring( nTest2 == 1234 &amp;&amp; nTest3 == 4321 ),
tostring( nTest2 == 9999 || nTest3 == 4321 )
) );

— Lua config table tests.
local config = config;
config[ &quot;test1&quot; ] = 1234;
config[ &quot;test2&quot; ] = &quot;Hello world!&quot;;

— LuaBind exposure test.
local pObject = CTest();
local nReturn = pObject:HelloWorld( 10, 90 );
print( string.format( &quot;[LuaBind Test] HelloWorld returned: %d&quot;, nReturn ) );

— Lua call from C++ test.
function SomeFunction ( )
print( string.format( &quot;Test function was called from C++!&quot; ) );
return 0;
end

— Create a test timer to tick every 5 seconds.
timer.Create( ‘TestTimer’, 5, 0,
function ( )
print( &quot;[Tick!] Test timer was pulsed! &quot; .. tostring( os.time() ) );
end
);

— Hook module test #1 – Event callback.
function ExampleHook_Callback ( name, health, armor )
print( string.format(
&quot;[Hooked] ExampleHook event was called: %s – %d – %d&quot;,
name, health, armor
) );
return 0;
end
hook.Add( &quot;ExampleHook&quot;, &quot;ExampleHook_Test&quot;, ExampleHook_Callback );

— Hook module test #2 — WindowProc.
function LuaWindowProc ( hWnd, uMsg, wParam, lParam )
— WM_CHAR
if( uMsg == 0x0101 ) then
— User pressed F1.
if( ( wParam &amp; 0xFFFF ) == 0x70 ) then
print( &quot;[LuaWindowProc] User pressed F1!&quot; );
end
end

return 0;
end
hook.Add( &quot;WindowProc&quot;, &quot;WindowProcLua&quot;, LuaWindowProc );

print( string.format( &quot;test.lua – Script finished at: %d&quot;, os.time() ) );

I personally don’t suggest handling the window procedure through Lua as it can get laggy depending on how indepth your application is. This was personally just for testing events and stuff though on my part.

I wrote a wrapper for Lua to handle a more functional method of calling things in Lua, handling the hook module, and to easily integrate Lua with a full-scale project. I’m sure it has it’s flaws and I’m not a professional coder so I’m sure things could be done differently. I’m not one to do templated coding as well so I know parts of this could be templated too. Here’s the header of what I got done so far:


/**
 * ScriptManager.h
 * (c) atom0s 2010 [atom0s@live.com]
 *
 * This is a simple singleton wrapper for Lua to easily embed Lua into projects.
 * This class is not finalized and is subject to change without notice!
 *
 * This class makes use of:
 * - boost      : http://www.boost.org/
 * - Lua        : http://www.lua.org/
 * - Luabind    : http://www.rasterbar.com/products/luabind.html
 *
 */

#pragma once

#ifndef __SCRIPTMANAGER_H_INCLUDED__
#define __SCRIPTMANAGER_H_INCLUDED__

#define STRICT
#define WIN32_LEAN_AND_MEAN

#include &lt;Windows.h&gt;
#include &lt;string&gt;

#include &lt;boost/smart_ptr.hpp&gt;

#pragma comment( lib, &quot;lua5.1.lib&quot; )
extern &quot;C&quot;
{
	#include &lt;lua.h&gt;
	#include &lt;lualib.h&gt;
	#include &lt;lauxlib.h&gt;
}

#pragma comment( lib, &quot;luabindd.lib&quot; )
#include &lt;luabind/luabind.hpp&gt;

#include &quot;Logger.h&quot;


/**
 * Validates the given Lua state is initialized.
 *
 * @param s			Current Lua state.
 * @param r			Return value if state is not valid.
 */
#define STATE_CHECK( s, r ) if( !s ) return r;

/**
 * Checks the Lua stack for stray items.
 *
 * @param pState	Current Lua state.
 * @noreturn
 */
inline void __CheckLuaStack( lua_State* pState )
{
	// Obtain stack count.
	int nStack = lua_gettop( pState );
	if( nStack &gt; 0 )
	{
		Logger::instance()-&gt;Log( &quot;[LUA:WARNING] Lua stack was not properly cleared!&quot; );
		for( int x = 1; x &lt;= nStack; x++ )
		{
			int nType = lua_type( pState, -1 );
			Logger::instance()-&gt;Log( &quot;[LUA:STACK] (%d) %s&quot;, x, lua_typename( pState, nType ) );
		}

		lua_pop( pState, nStack );
		Logger::instance()-&gt;Log( &quot;-------------------------------------------------&quot; );
	}
}

/**
 * Cleans the Lua stack.
 *
 * @param pState	Current Lua state.
 * @noreturn
 */
inline void __CleanLuaStack( lua_State* pState )
{
	int nStack = lua_gettop( pState );
	if( nStack &gt; 0 ) lua_pop( pState, nStack );
}

/**
 * Prints the current error on the stack.
 *
 * @param pState	Current Lua state.
 * @noreturn
 */
inline void __PrintStackError( lua_State* pState )
{
	int nStack = lua_gettop( pState );
	if( nStack == 1 &amp;&amp; ( lua_type( pState, -1 ) == LUA_TSTRING ) )
	{
		const char* pMessage = lua_tostring( pState, -1 );
		if( pMessage != NULL )
			Logger::instance()-&gt;Log( &quot;[LUA:ERROR] %s&quot;, pMessage );
        lua_pop( pState, 1 );
	}
}


/**
 * ScriptManager
 *
 * Lua script manager class.
 */
class ScriptManager
{
	static boost::shared_ptr&lt; ScriptManager &gt; m_vInstance;
	lua_State* m_vState;

public:
	static boost::shared_ptr&lt; ScriptManager &gt; instance( void );

public:
	ScriptManager				( void );
	~ScriptManager				( void );

public:
	HRESULT Initialize			( void );
	HRESULT Release				( bool bCollect = false );

public:
	HRESULT RunScript			( const std::string&amp; strFile );
	HRESULT RunString			( const std::string&amp; strScript );

public:
	bool FunctionExists			( const std::string&amp; strFunction );
	bool TableExists			( const std::string&amp; strTable );
	bool TableMemberExists		( const std::string&amp; strTable, const std::string&amp; strMember );
	bool VariableExists			( const std::string&amp; strVariable );

public:
	bool CallFunction			( const std::string&amp; strFunction );
	bool CallFunction			( int nArgCount = 0 );

public:
	bool PushFunction			( const std::string&amp; strFunction );
	bool PushTable				( const std::string&amp; strTable );
	bool PushField				( const std::string&amp; strField );
	bool PushString				( const std::string&amp; strParam );
	bool PushNumber				( int nParam );
	bool PushBoolean			( bool bParam );
	bool PushPointer			( void* lpParam ); // LUA_TLIGHTUSERDATA
	bool PopStack				( int nCount );

public:
	HRESULT SetGlobal			( const std::string&amp; strKey, std::string&amp; strValue );
	HRESULT SetGlobal			( const std::string&amp; strKey, int nValue );
	HRESULT SetGlobal			( const std::string&amp; strKey, bool bValue );
	HRESULT SetGlobal			( const std::string&amp; strKey, void* lpValue ); // LUA_TLIGHTUSERDATA

public:
	HRESULT GetConfigValue		( const std::string&amp; strKey, std::string&amp; strResult );
	HRESULT SetConfigValue		( const std::string&amp; strKey, const std::string&amp; strValue );

	HRESULT GetConfigValue		( const std::string&amp; strKey, int&amp; nResult );
	HRESULT SetConfigValue		( const std::string&amp; strKey, int nValue );

	HRESULT GetConfigValue		( const std::string&amp; strKey, bool&amp; bResult );
	HRESULT SetConfigValue		( const std::string&amp; strKey, bool bValue );

	HRESULT GetConfigValue		( const std::string&amp; strKey, void** lpResult );
	HRESULT SetConfigValue		( const std::string&amp; strKey, void* lpValue );

public:
	lua_State* GetState			( void ) { return this-&gt;m_vState; }
};


class CTest
{
public:
	CTest( void ) { }
	~CTest( void ) { }

	int HelloWorld( int nArg1, int nArg2 )
	{
		return ( nArg1 + nArg2 );
	}
};

#endif // __SCRIPTMANAGER_H_INCLUDED__

So basically at the moment I’ve just fixated myself with Lua stuff, learning as much about it as I can, while looking for some usages I may have for it later down the line with coding.

Hello Old Friend…

Wow, I really have not touched this blog in ages. Been pretty occupied with various projects and such that I haven’t had time to really sit down and post anything like I would like to do more often. Sadly, the majority of my current programming projects have been small things that really need no mention.

To start things off in this quick entry; as you can see; there is now a new skin on this blog. I decided time to change since I finally came back to give some life to this blog and will attempt to use it a bit more often again. So why not update its looks as well?

Job status; currently I am still doing freelance programming for anything that peeks my interests. A friend and I started a small company which we are currently developing an RSS/Atom reader for the Windows Mobile 7 phone system, which we plan to make as dynamic as possible to extend into supporting other open sourced API such as Twitter, Facebook, Myspace, etc. and any other requested things that we are able to integrate and such.

We were doing some ZuneHD development which I did mention directly to a few people, however that did fall through. Due to the lack of support on the device from Microsoft, and it’s limitations, we have decided against attempting to develop anything major on it unless it gets the much needed updates and attention it deserves. Sadly, the device is very capable of some nice things, including 3D gaming, but, without the support and needed developer features from Microsoft, a developer can only do so much with the limitations in place.

Random Projects
So here’s some quick information on some various projects I have done since I last posted here..

psofix (prev. known as psohax)
If you haven’t followed that project at all, I have renamed it to psofix. This was due to the number of people whom mentioned that they were scared of using it due to the name including hax. Because the projects main purpose was to fix bugs in the game, I renamed it to psofix. The project is now at version 1.4, which, I sadly have no time or interest to do much to it anymore. The base is done for it and the plugin interface works great so if others with to develop on it they can. But for the most part, the game is dead, and so is the project. (I will toss updates if something major is found to be broken etc. though.)

Old projects (patchLib, FontFactory, etc.)
Sadly, I’ve lost all interest in doing anything with these again. FontFactory had potential and a friend and I were really interested in working on a full blown GUI library for possible commercial release, but, due to the amount of time between the idea and him not having a computer, that idea is pretty much gone. I personally don’t have the time to devote to that project either with my company now with a friend so things for that idea are on hold indefinitely.

patchLib was going to be what I was going to work on though but thats on hold now as well. I figured out how to draw standard controls ontop of a GDI object rendered using UpdateLayeredWindow which was going to bring a much needed update to patchLib to allow standard control support, but there are still some limitations I ran into that I wanted to get squared away before working on the newer version of that. However I lost interest to work on it and its now on the back burner.

Visual Studio 2010
It’s finally launched and released fully, and I must say I love it. I’ve been using it for a few weeks now and the performance over the previous versions is very noticeable and much needed. I love the overhaul and look of the IDE, the redone features that needed reworking such as intellisense and project parsing. The overall speed of the IDE is great. Microsoft did a great job with this release. Not to say previous versions were terrible, but this one is definitely above the rest.

Recent Randoms
For a lack of a better title, randoms.. things that I have been doing randomly programming wise.

bhop_bundle
A bundled plugin for SourceMod that I wrote in SourcePawn language. I coded this specifically for a Counter-Strike: Source server that I host for a popular gamemode in CS:S called bunny hopping. The plugin include various features such as:
noblock: prevents players from colliding and blocking each other.
nodamage: prevents players from taking damage; including fall damage and world damage from map entities.
checkpoints: fully done checkpoint system allowing an n number of checkpoints to be stored and reused.
menu: allowing all these features to be used; toggled; etc.
autobhop: allowing players to automatically jump to bhop to help learn or to relax and have fun.

rpchat
An addon for Garrys Mod servers to have a roleplay style chat box which some are familiar with from a popular gamemode called PERP. Since none of the other chatbox addons/mods looked good or similar, I recreated it from scratch, giving it a more dynamic approach to easily add chat modes and commands with ease. Since I am new to GMod coding I have no intentions on releasing this as I want to ensure how I approached it is proper and non-intensive since the system uses network messages to update clients of new commands added and such rather then things being hard-coded.

Misc
Some random things I’ve helped others with in their projects, a loader for a game, an injector, etc. Nothing worth mentioning just some small things here and there.

That pretty much sums up what I’ve been doing lately. Hopefully I can have some more exciting things to post here later on.

New Skin; New Project; Blah!

Decided to change the skin again, this ones more open and shows code better. Sadly I can’t use a syntax highlighting script on here since they don’t allow plugins on the free WordPress hosting. And I’m not paying for a blog. (Might move to my own server if I care enough to do it, we’ll see.) Anyway, went with a bright theme for a change, the dark theme was a bit depressing and make the blog seem dead, granted it basically is.

New Project.. I started a small hook for an old game I used to play and hack. Phantasy Star Online. The project is named psopchax for the lack of creativity that I have and that I hate naming stuff. The main purpose of the hook isn’t for hacking though, which kinda throws it off some, the main purpose is to fix bugs inside the game, create a true windowed mode for the game, and extend features to the plugin interface.

The game was coded to specifically run fullscreen, no windowed mode option was made in the game. So this creates various other problems when forcing the game into a window.

– The game uses non-exclusive rights to the keyboard with DirectInput, meaning the game receives all key presses regardless if the window is in focus.
– The game does not allow typing in ENEU systems without the user installing the Windows IME. (The game was not released for English players.)
– The game forces itself into focus to prevent players from alt+tabbing while in fullscreen.
– The mouse is “attached” to the game while it is running, any click outside the window results in the mouse rubber-banding back onto the window.

psopchax fixes all these problems, and more.

– Fixes the game to run windowed, flawlessly. ( I use the term flawlessly losely. )
– Fixes the game from forcing itself into focus.
– Fixes the game from preventing typing with out the IME. (Can type without it now.)
– Fixes the game from hogging the mouse.
– Fixes the game from connecting to the SEGA servers to connect to any server you specify.
– Exposes a plugin interface to allow creation of extended features.
– Exposes various events to a plugin interface. (Direct3D, WndProc, etc.)
– Has in-game console rendered to allow users to easily access commands, manage plugins, etc.

psopchax is currently using the following outside resources:
– Boost [bind, foreach, function, serialization, shared_ptr]
– Detours 2.1
– Direct3D 8.0 SDK
– FontFactory
— FreeType v2

A screenshot of it in action, taken prior to the v1.1.0 public beta:
psopchax 1.1.0 beta

Overall, the project came together fairly quickly and worked out as planned which is a nice surprise. The ingame console was not part of my original idea for the project and I was actually writing out, in my head, methods to communicate externally with the hook using some IPC method such as pipes, mmf, etc. I decided to use my FontFactory project, even though it does have a few bugs, since the font looks like shit regardless in this game. So the actual bugs of FontFactory aren’t even noticed which makes it useful. 😀

The inner workings of the hook consist of basic detouring to hook Direct3D8, DirectInput8, and a few other API for helping with the true windowed mode. The hook uses various singleton classes for easier access across the hook, exposing base interfaces of the singletons to the plugins. This was not how the original hook was coded. Once I finished the first write out of the hook, the plugin interface was thought-out based on the very nice plugin interface tutorial series by Dr.Dobb’s here:
http://www.ddj.com/cpp/204202899

In the end, I am fairly pleased with how the project turned out, and how fast I got it done and ready for release. there are various aspects that can be done a lot better, I’m sure of it, I’m not the best programmer ever or anything. I enjoy what I make though, and almost always learn something new in the process. This was a nice learning experience creating the plugin interface, and my first time coding singletons. They are very useful and I will definitely make use of them more in the future.

Hopefully I will post a bit more often here, including code snippets and such for various purposes.

Cheers to anyone that actually reads this.

~atom0s

Starting Day…

I decided to start a WordPress blog rather then run a private forum on a home machine for a small blog to keep track of my current work to later be compiled into a real blog.

This blog will basically be used for developing purposes of any project I am currently working on. Mainly, the Direct3D hook and Direct3D8 things I have been working on recently.

This is mainly just for me to have to record ideas, thoughts, code, and share information with anyone that is interested. I am not expecting to have much traffic other then my own, nor expecting for people to comment on thing. But feel free to if you want.