Page 14 of 34

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 2:45 pm
by jayn23
05SpeedMaster wrote: Mon May 03, 2021 2:32 pm
Ivenend wrote: Mon May 03, 2021 1:33 pm Do you have any idea how to defeat the CRC check of GR2?
I have a Script for 010 that will check AND correct the CRC.
:)
If needed I can add CRC correction option to my script shouldn't be to difficult

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 2:49 pm
by Ivenend
05SpeedMaster wrote: Mon May 03, 2021 2:32 pm
Ivenend wrote: Mon May 03, 2021 1:33 pm Do you have any idea how to defeat the CRC check of GR2?
I have a Script for 010 that will check AND correct the CRC.
:)

:woah:

Is it possible for you to share your script?

Or could you tell me where is CRC information in GR2 and from where to where the CRC will check, so I can caculate by myself?

BTW I think GR2 use CRC-32, right?

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 2:55 pm
by 05SpeedMaster
Skip the first 104 bytes and do a CRC-32
The CRC is at 28h

And older version of AOE3 started the CRC count by skipping the first 88 bytes.

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 3:00 pm
by timtim
Ivenend wrote: Mon May 03, 2021 2:18 pm
timtim wrote: Mon May 03, 2021 2:11 pm I tried to view|convert GR2 Age of Empires 3 - Definitive Edition files in Noesis 4.442 both with both Reader plugin ver. 1.2.1 and ver. 1.3 but it wasn't successful.
I tried different ways: before and after https://github.com/nikita322/GrannyConverter2.11.8, without/with additional copying granny2.lib from nikita322 converter but it always ends with this error:
Image
You probably just need a v2.11.8 granny2.dll.

With this version of granny2.DLL in your Noesis folder, you can open GR2 from Age of Empires 3 - Definitive Edition directly.
Still no luck, with granny2.dll only in plugins folder Noesis doesn't see gr2 files as known format. Here is two versions of the same model for reference - original and converted v2.11.8 gr2:
https://drive.google.com/drive/folders/ ... sp=sharing

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 3:05 pm
by 05SpeedMaster
Both open for me.
granny2.dll needs to be in the noesis folder with Noesis.exe
NOT in the plug ins folder

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 3:28 pm
by Ivenend
05SpeedMaster wrote: Mon May 03, 2021 2:55 pm The CRC is at 28h
Thanks.

I'm a noob, so sorry for further questions:

With your help, I sucessfully find out the CRC of great_sword_lod0.model (file included in my previous examples.rar). It is the 34 12 D1 B1, that's exactly the CRC shows up on Granny Viewer.
Image
05SpeedMaster wrote: Mon May 03, 2021 2:55 pm Skip the first 104 bytes and do a CRC-32
Does "Skip the first 104 bytes" means select start form byte 105[69h] and to the end of the file?
I did an CRC 32(both big Edian and little edian) in 010 Editor and the result is this, which doesn't match the 34 12 D1 B1. What did I do wrong?
Image

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 3:30 pm
by 05SpeedMaster
Ivenend,

Your example files are compressed so hex editing is not going to work.

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 3:33 pm
by 05SpeedMaster
Delete the 1st 104 bytes then CRC-32

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 3:39 pm
by 05SpeedMaster
//-----------------------------------
// v3.2.2 Script File
//
// File: GR2Checksum.1sc
// Revision: 2.0
// Purpose: Opens a GR2, performs the CRC32 checksum, and then closes the file.
//----------------------------------------------------------------------------------

TOpenFileNames f = InputOpenFileNames("Open File", "GR2 Files ( *.gr2 )|All Files ( *.* )");
if (f.count == 0) return;
int i, n;
n = FileCount();
for(i = 0; i < f.count; i++)
{
FileOpen(f.file.filename);
//Can lock to only certian GR2 files these being SH5
//if (ReadQuad(00h) != 3122020088697118249 || ReadQuad(08h) != -1233310138417810139) {
//if (ReadQuad(00h) != 1130805896766580664 || ReadQuad(08h) != 2161755714778591876) {
//MessageBox(idOk, "Error", "File is not GR2 or corrupted!");
//return;
//};
//};
if (ReadInt(20h) < 7) { MessageBox(idOk, "Error", "Old version of file!");
return;
};
};
if (!IsLittleEndian()) LittleEndian();
int32 existCRC[f.count], calcCRC[f.count], editCRC[f.count];
OutputPaneClear();
for (i = 0; i < f.count; i++)
{
FileSelect(i + n);
existCRC = ReadInt(28h);
calcCRC = Checksum(CHECKSUM_CRC32, 68h, (FileSize() - 104));
Printf(f.file.filename + ": Existing CRC - %x\n", existCRC);
Printf(f.file.filename + ": Calculated CRC - %x\n", calcCRC);
if (existCRC != calcCRC) {
if (MessageBox(idYes|idNo, "Attention", f.file.filename + "\n\nThe existing CRC is not \nequal to the calculated CRC !\nWould you like to edit ?") == idYes)
{
WriteInt(28h, calcCRC[i]);
FileSave();
editCRC[i] = ReadInt(28h);
Printf(f.file[i].filename + ": Edited CRC - %x\n", editCRC[i]);
};
};
};
if (MessageBox(idYes|idNo, "Attention", "Would you like to close files ?") == idYes)
{
for(i = 0; i < f.count; i++) {
FileSelect(i + n);
FileClose();
};
};
return;

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 3:52 pm
by Ivenend
05SpeedMaster wrote: Mon May 03, 2021 3:30 pm Ivenend,

Your example files are compressed so hex editing is not going to work.
That's sad.
Thank you anyway! Learned a lot from you about how CRC work in GR2.

Is it possible to decompress a BitKnit 2 compressed GR2?

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 3:57 pm
by 05SpeedMaster
//-----------------------------------
//--- 010 Editor v3.2.2 Binary Template
//
// File: GR2Template.bt
// Author: Privateer / TheDarkWraith
// Special Thanks to: Anvart
// Revision: 1
// Purpose: Defines a template for understanding GR2 files.
//
// Structues built from info obtained from Granny Viewer 2.8.33.0
// and the Granny Change log.
//-----------------------------------

#include "Header.h"


//---------------------------------------------

// Define the headers
LittleEndian();
SetBackColor( cLtRed );
GR2FILEHEADER GR2fh<hidden=false>;

SetBackColor( cBlue );
GR2INFOHEADER GR2_Info;
SetBackColor( cLtBlue );

// Display The Sections Information
SetBackColor( cRed );
SECTIONS SectionInfo[8];


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Header.h
// Define structures for Magic Block, header and Section Indexes in Gr2 files

typedef struct { // GR2fh
quad GR2Magic[2]<hidden=true>;
UINT HeaderSize<comment="Size of all information before the start of Section 0">;
LONG Unknown_info[3]<hidden=true,format=hex>;
} GR2FILEHEADER;

typedef struct { // GR2ih
UINT File_format_revision <format=decimal>;
UINT File_Size_in_bytes;
UINT CRC <format=hex,comment="CRC of file (from begin of section array up to EoF). Algoritm CRC-32">;
UINT SectionArrayOffset <bgcolor=0xffffb0,fgcolor=cRed,comment="Offset to section array">;
UINT SectionArrayCount <comment="Total number of sections">;
UINT Unknowns[4]<hidden=true,format=hex>;
UINT Tag<format=hex>;
UINT Unknown[8]<hidden=true,format=hex>;
} GR2INFOHEADER;

typedef struct { // Sectionsinfo
UINT Format<comment="Compression Format">;
UINT Pointer<format=hex,bgcolor=cLtGreen,comment="Start of section data">;
UINT True_Block_Size_in_file<comment="Compressed Data size">;
UINT Block_Size_In_file<comment="Actual amount of Data uncompressed">;
UINT Internal_Alignment<comment="offset">;
UINT Unknown[2]<bgcolor=cLtYellow,hidden=true>;
UINT Another_Pointer<format=hex,bgcolor=cLtGreen,comment="Will explain at a later date">;
UINT WTH[3]<bgcolor=cLtYellow,hidden=true>;
} SECTIONS;

/*Sections as used in SH5 GR2 files.
NOt all GR2 files follow this layout.

0 - MainSection
1 - RigidVertexSection
2 - RigidIndexSection
3 - DeformableVertexSection
4 - DeformableIndexSection
5 - TextureSection
6 - DiscardableSection
7 - UnloadedSection */

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 5:44 pm
by Ivenend
05SpeedMaster wrote: Mon May 03, 2021 3:30 pm Ivenend,

Your example files are compressed so hex editing is not going to work.
I managed to decompressed the two example files :D
https://drive.google.com/file/d/1HSnr67 ... sp=sharing

Could you or Jayn please check these files and see if you can find the opacity enable value?

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 6:07 pm
by 05SpeedMaster
I need a better explanation of where you are finding the values in GrannyViewer.
The complete path to follow.

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 6:33 pm
by Ivenend
05SpeedMaster wrote: Mon May 03, 2021 6:07 pm I need a better explanation of where you are finding the values in GrannyViewer.
The complete path to follow.
Material List - the last one in the list of material - right click - view in detail - ExtendedData

Re: Granny .GR2 Reader plugin for Noesis

Posted: Mon May 03, 2021 10:34 pm
by jayn23
Ivenend wrote: Sun May 02, 2021 1:18 am --------------

BTW Is it possible for you to make your D2R_texture plugin also supports exporting an image to .texture?

-------------
Well i got it working, had to do some reasrch, at least i finally know what MipMpas are now :mrgreen:
Let me know if exported textures are read correctly by game engine.

Before exporting image you must specify what format you want, can be done in 2 ways:
by invoking option in advanced option, or by editing script end choosing a TEX_TYPE.
Normal maps have red and green channels swapped in game, if you need to sawp channels you can invoke swizzle command.
Available Commands:
-DXT1
-DXT5
-BC4
-RGBA32
-SWIZZLE


Script now supports import/export for .texture
new version in a later post