Author Topic: I am planning on a new api and toolset...  (Read 3104 times)

0 Members and 1 Guest are viewing this topic.

Offline ModderJBS3

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
    • Email
I am planning on a new api and toolset...
« on: December 26, 2012, 01:19:43 PM »
I am planning on writing tools specifically with BG::EE in mind and eventually BG2:EE. I really like the idea of open sourcing my projects as well.

Right now I'm a little stumped though... In the key resource entries in the key file... a source index and either a tileset or non-tileset index can be set at the same time right? I think that's right. If I'm wrong then I wrote the below code for nothing.

void KeyResourceEntry::SetSourceIndex(unsigned long dwIndex)
    {
        const unsigned long dwMask = 0x00000FFF;
        const unsigned long dwShift = 20;

        const unsigned long dwTempValue = (dwIndex & dwMask) << dwShift;

        // now we invert the temp value, mask it off the value to zero the bits
        // then OR it in to set the value. (we have to do this or ORing the bits
        // might give us a bad value

        const unsigned long dwInvertedMask = 0x000FFFFF; // ~0xFFF00000;

        dwResourceLocator &= dwInvertedMask;

        // now or in the bit value

        dwResourceLocator |= dwTempValue;
    }
« Last Edit: December 26, 2012, 02:27:24 PM by ModderJBS3 »

Offline Solaufein

  • Lord of the Realms
  • Administrator
  • Level 5
  • *****
  • Posts: 5156
  • Karma: +127/-19
  • Gender: Male
  • The night is dark and full of terrors...
    • ICQ Messenger - 251194643
    • Yahoo Instant Messenger - gscott7833
    • View Profile
    • http://teambg.net
Re: I am planning on a new api and toolset...
« Reply #1 on: December 26, 2012, 03:55:31 PM »
Looks like a good idea, new tools are always welcomed.

My programming is non-existent these days. My knowledge is from the 2000-2002 time with VB and Java and I basically forgot all of that since I never used that knowledge beyond college.
My mods:
Dark Horizons
The Undying
Nikita
IWD2 store

Co-contributor:
Dark Side of the Sword Coast BG1 Weidu
Aurils Bane
Encounters
Saerileth
Baldur's Gate - Enhanced Edition beta tester
Baldur's Gate 2 - Enhanced Edition beta tester
Icewind Dale - Enhanced Edition beta tester

Offline ModderJBS3

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
    • Email
Re: I am planning on a new api and toolset...
« Reply #2 on: December 30, 2012, 09:04:52 AM »
Well I haven't had any time until today to write some code, but I found myself wanting to write some helper classes to make writing and debugging easier. So I am going to write a class library (open source of course) in C++ with these classes and functions. I want it to be stand alone so I'm not using STL or the CRT. I'm even going as far as overloading new and delete operators so we can track memory leaks easier. (it can be done with the CRT, but it's a pain in the butt to do) It will take me a week or so to finish this library, then I can get back on writing the code for BGEETools. I ran into some linker problems with MinGW and went back to VC++ 2010 and found I needed to download service pack 1 or I'd be further along on everything. To give you an idea of what I'm doing below is some C++ code of new and delete operators.

#include "StdAfx.hpp"
#include "WinJSA.hpp"

namespace
{
   WinJSA::CAllocationNode * FirstAllocationNode = 0;
   WinJSA::CAllocationNode * LastAllocationNode = 0;
   unsigned long long AllocationCount = 0;
   HANDLE DataMutex = ::CreateMutexW(0,FALSE,0);
}

void * operator new(unsigned int nSize) throw(WinJSA::CMemoryException)
{
   void * pRetValue = 0;

   ::WaitForSingleObject(DataMutex,INFINITE);

   const unsigned long long nAllocSize = static_cast<unsigned long long>(nSize) + sizeof(WinJSA::CAllocationNode);

   HANDLE hHeapHandle = ::GetProcessHeap();

   WinJSA::CAllocationNode * pNode = reinterpret_cast<WinJSA::CAllocationNode *>(::HeapAlloc(hHeapHandle,HEAP_ZERO_MEMORY,nAllocSize));

   if (pNode != 0)
   {
      if (FirstAllocationNode != 0)
      {
         LastAllocationNode->NextNode = pNode;
         pNode->PreviousNode = LastAllocationNode;

         ++AllocationCount;
      }
      else
      {
         FirstAllocationNode = pNode;
         LastAllocationNode = pNode;

         AllocationCount = 1;
      }

      pNode->AllocationSize = static_cast<unsigned long long>(nSize);
      pNode->FileName = __FILE__;
      pNode->LineNumber = __LINE__;

      WinJSA::CAllocationNode * pNode2 = pNode + 1;

      pRetValue = reinterpret_cast<void *>(pNode2);

      ::ReleaseMutex(DataMutex);
   }
   else
   {
      ::ReleaseMutex(DataMutex);

      WinJSA::CMemoryException udtException("Out of memory.",__FILE__,__LINE__);

      throw(udtException);
   }

   return pRetValue;
}

void operator delete(void * lpBuf)
{
   ::WaitForSingleObject(DataMutex,INFINITE);

   if (lpBuf != 0)
   {
      WinJSA::CAllocationNode * pNode = reinterpret_cast<WinJSA::CAllocationNode *>(lpBuf);
      --pNode;

      // remove the node from the list
      if (pNode->PreviousNode != 0)
      {
         pNode->PreviousNode->NextNode = pNode->NextNode;
      }
      else
      {
         FirstAllocationNode = pNode->NextNode;
      }

      if (pNode->NextNode != 0)
      {
         pNode->NextNode->PreviousNode = pNode->PreviousNode;
      }
      else
      {
         LastAllocationNode = pNode->PreviousNode;
      }

      --AllocationCount;

      HANDLE hHeapHandle = ::GetProcessHeap();

      // free the memory
      void * lpBuffer = reinterpret_cast<void *>(pNode);

      ::HeapFree(hHeapHandle,0,lpBuffer);
   }

   ::ReleaseMutex(DataMutex);
}

Offline Amy

  • Global Moderator
  • Level 3
  • *****
  • Posts: 1235
  • Karma: +85/-10
  • Gender: Female
    • View Profile
Re: I am planning on a new api and toolset...
« Reply #3 on: January 06, 2013, 12:11:02 AM »
Looks complex. Will this work for the older games?

Offline BlakeDrapeta

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: I am planning on a new api and toolset...
« Reply #4 on: January 29, 2013, 06:27:06 AM »
This is really needed, since from the last several hours I've determined that a few of tools don't work with BGEE (the only ones I've tried anyway, since I'm mainly concerned with high resolution map making), and a few don't like Windows 7. I'm going to just use the files from the original BGtotsc for now in making high resolution content until we have working tools.
« Last Edit: January 29, 2013, 06:29:22 AM by BlakeDrapeta »