Category Archives: Games

Grim Dawn File Archive / Database Extractors

I’ve recently bought Grim Dawn after wanting an offline ARPG to play while my internet is utter shit or offline. I stumbled across Grim Dawn by accident doing some Google searches looking for something that has a similar Diablo feel to it. GD happens to be by the makers of Titan Quest, which I did enjoy somewhat when I was younger, however I never really got too in depth with playing it. But from the look of the game having that Diablo 2 look and feel, I wanted to give it a try.

Fast forward to now, I’ve been personally interested in the game data files to see how things are stored, what is where, and so on as a local lookup for information about the game, such as where monsters spawn, what they drop, and such. Which lead to the creation of the two following tools.

grimarc – Grim Dawn Archive File Extractor (.arc)
This is a simple tool to extract the .arc archive files for Grim Dawn.
https://github.com/atom0s/grimarc

grimarz – Grim Dawn Database File Extractor (.arz)
This is a simple tool to extract the .arz database files for Grim Dawn.
https://github.com/atom0s/grimarz

At this time, these tools are simply for static analysis locally, they do not offer any ability to edit, read, modify or repackage the files they have since extracted. My interest is simply in seeing the content of the files, not to modify them.

Terraria – Steamless Loading

Disclaimer: Usage of a method to load the game list this allows you to run without Steam. This means the game can be copied onto other machines without purchasing it. I do not condone in piracy. I simply made this because I was sick of Steam for a while. I take no responsibility in what you do with this information.

Since Terraria is a managed application, we can easily import it into a project and reference the main class. With this we can initiate an instance of the main class and effectively load the game through our own app. With this we can skip the entire launching method that is called by the application when it’s asked to start (Main(..)).

So in turn we land up with:

using System;
using System.IO;
using System.Reflection;
using Microsoft.Xna.Framework;

namespace tLock
{
#if WINDOWS || XBOX
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            // Set Terraria's Path..
            String strRealPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\Steam\steamapps\common\terraria"; //"C:\Program Files (x86)\Steam\steamapps\common\terraria";
            Directory.SetCurrentDirectory(strRealPath);

            // Run our game..
            var tLock = Assembly.GetExecutingAssembly().GetType("tLock.Hook", true, true);
            (Activator.CreateInstance(tLock) as Game).Run();
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            using (FileStream fStream = new FileStream("errorlog.txt", FileMode.CreateNew, FileAccess.ReadWrite))
            {
                using (StreamWriter sWriter = new StreamWriter(fStream))
                {
                    sWriter.Write(((Exception)e.ExceptionObject).Message);
                }
            }
        }
    }
#endif
}

Then we need to add our hook class which tells the game were to locate the content. This also allows you alter the game while it plays to do a ton of other stuff. (Not covered in this post though.)

Hook.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Terraria;

namespace tLock
{
    public class Hook : Terraria.Main
    {
        protected override void Initialize()
        {
            // Reset the content directory..
            Content.RootDirectory = Environment.CurrentDirectory + "\Content\";

            // Base initialization..
            base.Initialize();
        }

        protected override void LoadContent()
        {
            base.LoadContent();
        }

        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }
    }
}

Once compiled, drop in the same directory as Terraria.exe and use your app to launch the game. Tada~ no more Steam

Desktop Cleanup – Old Code

Continuing with the cleanup today; here are some other snippets from some SourceMod scripts I wrote for my private servers:

Double Damage – Hook to increase the damage of all weapons (x2).

/**
 * Player Hurt Event
 */
public Action:OnPlayerHurt_Event( Handle:event, const String:name[], bool:dontBroadcast )
{
	new attacker = GetClientOfUserId( GetEventInt( event, "attacker" ) );
	if( IsClientInGame( attacker ) && !IsFakeClient( attacker ) )
	{
		new dmgarmor 	= GetEventInt( event, "dmg_armor" );
		new dmghealth 	= GetEventInt( event, "dmg_health" );
		
		dmgarmor 	= dmgarmor * 2;
		dmghealth 	= dmghealth * 2;
		
		SetEventInt( event, "dmg_armor", dmgarmor );
		SetEventInt( event, "dmg_health", dmghealth );
	}
	return Plugin_Continue;
}

// Hook:
HookEvent( "player_hurt", OnPlayerHurt_Event, EventHookMode_Pre );

Auto-bhop – Forces clients to continue jumping while holding their jump button.

public Action:OnPlayerRunCmd( client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon )
{
	if( IsPlayerAlive( client ) && IsClientInGame( client ) )
	{
		if( buttons & IN_JUMP )
		{
			if( ! ( GetEntityFlags( client ) & FL_ONGROUND ) )
			{
				buttons &= ~IN_JUMP;
			}
		}
	}
	
	return Plugin_Continue;
}

Runes of Magic

Since I don’t have much to post about I do want to keep updating this blog a bit more frequently. So here is some old information I worked on from an MMO called Runes of Magic. This is some old info so it could be outdated, so if it doesn’t line up fully its probably due to updates.

Player structure: (Fairly certain all mobs used this, but I don’t fully remember.)

typedef struct _MOBENTRY {

    unsigned long   _unk1;          // 0x00 - Pointer / Id?
    unsigned long   WarpStruct;     // 0x04 - Warp structure x/z/y etc.
    unsigned char   _unk2[12];      // 0x08 - Unknown Data
    unsigned long   ObjectId;       // 0x14 - Object identification?
    unsigned long   ObjectType;     // 0x18 - Object Type Flag
    unsigned long   _unk3;          // 0x1C - Seems to always be 1.
    unsigned long   _unk4;          // 0x20 - Seems to be a pointer to something.
    unsigned long   _unk5;          // 0x24 - Seems to always be 0.
    float           WorldX;         // 0x28 - Position X in world. (Read-only)
    float           WorldZ;         // 0x2C - Position Z in world. (Read-only)
    float           WorldY;         // 0x30 - Position Y in world. (Read-only)
    float           Heading1;       // 0x34 - Looking direction. (Camera left/right.)
    float           Camera1;        // 0x38 - Camera position up/down.
    float           Heading2;       // 0x3C - Looking direction. (Unsure, it turns your char as well.)
    float           Speed;          // 0x40 - Speed
    unsigned char   _unk6[16];      // 0x44 - Unknown Data
    float           ModelTilt1;     // 0x54 - Model tilt axis. (Backward.) (Read-only)
    float           _unk7;          // 0x58 - Forced 0.
    unsigned long   _unk8;          // 0x5C - Unknown
    float           ModelTilt2;     // 0x60 - Model tilt axis. (Backward.) (Editable)
    float           _unk9;          // 0x64 - Changes _unk7 - model positioning possibly?
    float           _unk10;         // 0x68 - Unknown
    float           _unk11;         // 0x6C - Unknown
    float           ModelScale1;    // 0x70 - Scaling of model. (1 = normal, 2 = huge, 0 = tiny.)
    float           ModelScale2;    // 0x74 - Scaling of model. (Possible multipler?)
    float           Transparency;   // 0x78 - Model transparency. (1 = full, 0.5 = half, 0 = invis.)

    unsigned char   _unk12[532];    // 0x7C - Unknown Data
    
    char*           Name;           // 0x290
    char*           Title;          // 0x294
    char*           Guild;          // 0x298
};

Friend of mine and I worked hard to reverse the damage calculations for defense as well and came up with:

(This could also be invalid now, it was only off by around %0.098 when we tested and figured it out.)

modifier = 
	if( self-pattack &lt; target-pdef )
		penalty = (( self-pattack / target-pdef ) / target-pdef) * 100 
	else
		bonus = ((( self-pattack / target-pdef ) / self-pattack ) + 1 ) * 100

( 100 + modifier )% of ( self-damage / attack-speed ) = white_damage_hit

Just cleaning up my desktop and figured I’d post these in case anyone wants them.