Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 05.10.2005, 19:52   #1
MoSs
Архивный участник
 
Join Date: Jul 2005
Posts: 108
Default [Sharing] Torunes Geodata code ported to C#

Well I found on a numerous sites the C++ code made by torune and I decided to give it a go!

While examining the structure of existing geodata files found out a couple of bugs in the code :P

Since i mainly write my programs in C# i also ported it to that language.

The fixes are:
- Skips 54 bytes that is the input BMP file header
- Production of lvl1 geodata is first add 2 zero bytes then add the height. Torunes posted code was wrong, he added 1 zero byte then height and again 1 zero byte

Hope this helps to get you started making a good geo generator

Credits go to Torune

Code:
/*
 * Original GeoData gen code by Torune
 * fixed and ported to C# by MoSs
 */
using System;
using System.IO;

namespace GeoGen
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			uint [] MAP_HEIGHT = {
				//38-3F
				(0xE318E318), (0xE46DE46D), (0xE5C2E5C2), (0xE717E717),
				(0xE86CE86C), (0xE9C1E9C1), (0xEB16EB16), (0xec6bec6b),
				//40-4f
				(0xedc0edc0), (0xef15ef15), (0xf06af06a), (0xf1bff1bf),
				(0xf314f314), (0xf469f469), (0xf5bef5be), (0xf713f713),
				(0xf868f868), (0xf9bdf9bd), (0xfb12fb12), (0xfc67fc67),
				(0xfdbcfdbc), (0xff11ff11), (0x00670067), (0x01bc01bc),
				//50-5f
				(0x03110311), (0x04660466), (0x05bb05bb), (0x07100710),
				(0x08650865), (0x09ba09ba), (0x0b0f0b0f), (0x0c640c64),
				(0x0db90db9), (0x0f0e0f0e), (0x10631063), (0x11b811b8),
				(0x130d130d), (0x14621462), (0x15b715b7), (0x170c170c),
				//60-6f
				(0x18611861), (0x19b619b6), (0x1b0b1b0b), (0x1c601c60),
				(0x1db51db5), (0x1f0a1f0a), (0x205f205f), (0x21b421b4),
				(0x23092309), (0x245e245e), (0x25b325b3), (0x27082708),
				(0x285d285d), (0x29b229b2), (0x2b072b07), (0x2c5c2c5c),
				//70-7f
				(0x2db12db1), (0x2f062f06), (0x305b305b), (0x31b031b0),
				(0x33053305), (0x345a345a), (0x35af35af), (0x37043704),
				(0x38593859), (0x39ae39ae), (0x3b033b03), (0x3c583c58),
				(0x3dad3dad), (0x3f023f02), (0x40574057), (0x41ac41ac),
				//80-8f
				(0x43014301), (0x44564456), (0x45ab45ab), (0x47004700),
				(0x48554855), (0x49aa49aa), (0x4aff4aff), (0x4c544c54),
				(0x4da94da9), (0x4efe4efe), (0x50535053), (0x51a851a8),
				(0x52fd52fd), (0x54525452), (0x55a755a7), (0x56fc56fc),
				//90-9f
				(0x58515851), (0x59a659a6), (0x5afb5afb), (0x5c505c50),
				(0x5da55da5), (0x5efa5efa), (0x604f604f), (0x61a461a4),
				(0x62f962f9), (0x644e644e), (0x65a365a3), (0x66f866f8),
				(0x684d684d), (0x69a269a2), (0x6af76af7), (0x6c4c6c4c),
				//a0-a5
				(0x6da16da1), (0x6ef66ef6), (0x704b704b), (0x71a071a0),
				(0x72F572F5), (0x744A744A)
				};
			
			uint [] RGB = {
				//0x3
				(0x38), (0x39), (0x3a), (0x3b), (0x3C), (0x3D), (0x3E), (0x3F),
				//0x4
				(0x40), (0x41), (0x42), (0x43), (0x44), (0x45), (0x46), (0x47),
				(0x48), (0x49), (0x4a), (0x4b), (0x4c), (0x4d), (0x4e), (0x4f),
				//0x5
				(0x50), (0x51), (0x52), (0x53), (0x54), (0x55), (0x56), (0x57),
				(0x58), (0x59), (0x5a), (0x5b), (0x5c), (0x5d), (0x5e), (0x5f),
				//0x6
				(0x60), (0x61), (0x62), (0x63), (0x64), (0x65), (0x66), (0x67),
				(0x68), (0x69), (0x6a), (0x6b), (0x6c), (0x6d), (0x6e), (0x6f),
				//0x7
				(0x70), (0x71), (0x72), (0x73), (0x74), (0x75), (0x76), (0x77),
				(0x78), (0x79), (0x7a), (0x7b), (0x7c), (0x7d), (0x7e), (0x7f),
				//0x8
				(0x80), (0x81), (0x82), (0x83), (0x84), (0x85), (0x86), (0x87),
				(0x88), (0x89), (0x8a), (0x8b), (0x8c), (0x8d), (0x8e), (0x8f),
				//0x9
				(0x90), (0x91), (0x92), (0x93), (0x94), (0x95), (0x96), (0x97),
				(0x98), (0x99), (0x9a), (0x9b), (0x9c), (0x9d), (0x9e), (0x9f),
				//0xA
				(0xa0), (0xa1), (0xa2), (0xa3), (0xa4), (0xa5)
				};
			
			byte BREAK = 0;
			
			byte [] MAP_HEAD = { 23, 25, 128 }; //this would be your XX_YY_conv.dat signature
			
			string MAP_NAME = "output_conv.dat";
			string BmpFile = "lineage2.bmp";
			
			byte [] HEADER = { 0,16,0,0,0,0,0,0,0,1,0,0,0,1,0 };
			
			int ch = 0;
			
			BinaryReader fin = new BinaryReader(new FileStream(BmpFile, System.IO.FileMode.Open));
	        BinaryWriter fout = new BinaryWriter(new FileStream(MAP_NAME, System.IO.FileMode.Create));


	       for(int i=0;i<MAP_HEAD.Length;i++) fout.Write(MAP_HEAD[i]);
	       for(int i=0;i<HEADER.Length;i++) fout.Write(HEADER[i]);
	        
	       //skipping 54 bytes BMP file header
	       for(int i=0;i<54;i++) fin.ReadByte();
	       
	       while(fin.BaseStream.Position < fin.BaseStream.Length){
	       		ch=fin.ReadByte(); // R
	        	fin.ReadByte(); // G skipping
	        	fin.ReadByte(); // B skipping
	        	for(int i=0; i<110; i++){
	        		if(ch==RGB[i]){
	        			fout.Write(BREAK);	        			   
	        			fout.Write(BREAK);
	        			fout.Write(MAP_HEIGHT[i]);	        			  			
	        		}
	        	}
	        }
	        
	        fout.Close();
	        fin.Close();
	        
		}
	}
}
MoSs is offline  
Old 06.10.2005, 02:14   #2
Alien003
Архивный участник
 
Join Date: Jun 2005
Posts: 143
Default

I havent read much about how geodata works .. so i cant say anyhting about the it.

but what color are you trying to read from the bmp?

Code:
              ch=fin.ReadByte(); // R
              fin.ReadByte(); // G skipping
              fin.ReadByte(); // B skipping
BMP uses a color sequencing of BGR, not RGB
What is wrong? the comments or the code?
Alien003 is offline  
Old 06.10.2005, 09:45   #3
MoSs
Архивный участник
 
Join Date: Jul 2005
Posts: 108
Default

its grayscale any color would do, all 3 colors have the same value
MoSs is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 19:17.