Add rayman2 source files

This commit is contained in:
2024-09-18 02:33:44 +08:00
parent bcc093f8ed
commit fb036c54fd
14339 changed files with 2596224 additions and 0 deletions

View File

@@ -0,0 +1,197 @@
# Microsoft Developer Studio Project File - Name="SNA" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 5.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=SNA - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "Sna.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "Sna.mak" CFG="SNA - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "SNA - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "SNA - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE "SNA - Win32 Retail" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP Scc_ProjName ""$/cpa/tempgrp/SNA", KDEAAAAA"
# PROP Scc_LocalPath "."
CPP=cl.exe
!IF "$(CFG)" == "SNA - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "x:\cpa\lib"
# PROP Intermediate_Dir "Tmp\Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /G5 /W3 /GX /O2 /I "x:\Cpa\Public" /I "t:\dxsdk\sdk\inc" /I "x:\Cpa\Main" /I "x:\cpa\public\sna" /I "x:\cpa\public\gam" /D "NDEBUG" /D "USE_PROFILER" /D "USE_IPT_DX5" /D "VISUAL" /D "WIN32" /FD /c
# SUBTRACT CPP /Fr /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\..\lib\SNAP5_vr.lib"
!ELSEIF "$(CFG)" == "SNA - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "x:\cpa\lib"
# PROP Intermediate_Dir "tmp\debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c
# ADD CPP /nologo /G5 /MD /W3 /GX /Z7 /Od /I "x:\Cpa\Public" /I "t:\dxsdk\sdk\inc" /I "x:\Cpa\Main" /I "x:\cpa\public\sna" /I "x:\cpa\public\gam" /D "_DEBUG" /D "USE_PROFILER" /D "MTH_CHECK" /D "CPA_WANTS_EXPORT" /D "VISUAL" /D "WIN32" /FD /c
# SUBTRACT CPP /Fr /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"..\..\lib\SNAP5_vd.lib"
!ELSEIF "$(CFG)" == "SNA - Win32 Retail"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "SNA___Wi"
# PROP BASE Intermediate_Dir "SNA___Wi"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "x:/cpa/lib"
# PROP Intermediate_Dir "tmp/retail"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /G5 /MD /W3 /GX /O2 /I "x:\Cpa\Public" /I "t:\dxsdk\sdk\inc" /I "x:\Cpa\Main" /I "x:\cpa\public\sna" /I "x:\cpa\public\gam" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
# SUBTRACT BASE CPP /Fr /YX
# ADD CPP /nologo /G5 /W3 /GX /O2 /I "x:\Cpa\Public" /I "t:\dxsdk\sdk\inc" /I "x:\Cpa\Main" /I "x:\cpa\public\sna" /I "x:\cpa\public\gam" /D "NDEBUG" /D "RETAIL" /D "USE_IPT_DX5" /D "VISUAL" /D "WIN32" /FD /c
# SUBTRACT CPP /Fr /YX
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo /out:"..\..\lib\SNAP5_vr.lib"
# ADD LIB32 /nologo /out:"..\..\lib\SNAP5_vf.lib"
!ENDIF
# Begin Target
# Name "SNA - Win32 Release"
# Name "SNA - Win32 Debug"
# Name "SNA - Win32 Retail"
# Begin Group "Sources"
# PROP Default_Filter ".c;.cpp;.cxx"
# Begin Source File
SOURCE=.\snafile.c
# End Source File
# Begin Source File
SOURCE=.\snaglob.c
# End Source File
# Begin Source File
SOURCE=.\snammg.c
# End Source File
# Begin Source File
SOURCE=.\snanoscr.c
# End Source File
# Begin Source File
SOURCE=.\snapoint.c
# End Source File
# Begin Source File
SOURCE=.\snarlt.c
# End Source File
# Begin Source File
SOURCE=.\snasnd.c
# End Source File
# Begin Source File
SOURCE=.\snasyn.c
# End Source File
# Begin Source File
SOURCE=.\snavig.c
# End Source File
# End Group
# Begin Group "Includes"
# PROP Default_Filter ".h;.hpp"
# Begin Source File
SOURCE=..\..\public\sna.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snadef.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snafile.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snaglob.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snammg.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snanoscr.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snapoint.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snarlt.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snasnd.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snasyn.h
# End Source File
# Begin Source File
SOURCE=..\..\public\SNA\snavig.h
# End Source File
# End Group
# Begin Source File
SOURCE=.\Sna.mak
# End Source File
# End Target
# End Project

View File

@@ -0,0 +1,458 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="SNA"
ProjectGUID="{EBBAD204-AA8B-4911-A74A-3FC16C4857F3}"
SccProjectName="&quot;$/cpa/tempgrp/SNA&quot;, KDEAAAAA"
SccAuxPath=""
SccLocalPath="."
SccProvider="MSSCCI:NXN alienbrain">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="x:\cpa\libd"
IntermediateDirectory=".\tmp\debug"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
OptimizeForProcessor="1"
AdditionalIncludeDirectories="x:\Cpa\Public,t:\dxsdk\sdk\inc,x:\Cpa\Main,x:\cpa\public\sna,x:\cpa\public\gam"
PreprocessorDefinitions="_DEBUG;USE_PROFILER;MTH_CHECK;CPA_WANTS_EXPORT;VISUAL;WIN32"
RuntimeLibrary="3"
PrecompiledHeaderFile=".\tmp\debug/SNA.pch"
AssemblerListingLocation=".\tmp\debug/"
ObjectFile=".\tmp\debug/"
ProgramDataBaseFileName=".\tmp\debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="1"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="x:\CPA\Libd\SNAP5_vd.lib"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="x:\cpa\lib"
IntermediateDirectory=".\Tmp\Release"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OptimizeForProcessor="1"
AdditionalIncludeDirectories="x:\Cpa\Public,t:\dxsdk\sdk\inc,x:\Cpa\Main,x:\cpa\public\sna,x:\cpa\public\gam"
PreprocessorDefinitions="NDEBUG;USE_PROFILER;USE_IPT_DX5;VISUAL;WIN32"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
PrecompiledHeaderFile=".\Tmp\Release/SNA.pch"
AssemblerListingLocation=".\Tmp\Release/"
ObjectFile=".\Tmp\Release/"
ProgramDataBaseFileName=".\Tmp\Release/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="..\..\lib\SNAP5_vr.lib"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Retail|Win32"
OutputDirectory="x:/cpa/lib"
IntermediateDirectory=".\tmp/retail"
ConfigurationType="4"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OptimizeForProcessor="1"
AdditionalIncludeDirectories="x:\Cpa\Public,t:\dxsdk\sdk\inc,x:\Cpa\Main,x:\cpa\public\sna,x:\cpa\public\gam"
PreprocessorDefinitions="NDEBUG;RETAIL;USE_IPT_DX5;VISUAL;WIN32"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
PrecompiledHeaderFile=".\tmp/retail/SNA.pch"
AssemblerListingLocation=".\tmp/retail/"
ObjectFile=".\tmp/retail/"
ProgramDataBaseFileName=".\tmp/retail/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLibrarianTool"
OutputFile="..\..\lib\SNAP5_vf.lib"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Sources"
Filter=".c;.cpp;.cxx">
<File
RelativePath="snafile.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Retail|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="snaglob.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Retail|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="snammg.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Retail|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="snanoscr.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Retail|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="snapoint.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Retail|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="snarlt.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Retail|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="snasnd.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Retail|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="snasyn.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Retail|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
<File
RelativePath="snavig.c">
<FileConfiguration
Name="Debug|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
<FileConfiguration
Name="Retail|Win32">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""/>
</FileConfiguration>
</File>
</Filter>
<Filter
Name="Includes"
Filter=".h;.hpp">
<File
RelativePath="..\..\public\sna.h">
</File>
<File
RelativePath="..\..\public\SNA\snadef.h">
</File>
<File
RelativePath="..\..\public\SNA\snafile.h">
</File>
<File
RelativePath="..\..\public\SNA\snaglob.h">
</File>
<File
RelativePath="..\..\public\SNA\snammg.h">
</File>
<File
RelativePath="..\..\public\SNA\snanoscr.h">
</File>
<File
RelativePath="..\..\public\SNA\snapoint.h">
</File>
<File
RelativePath="..\..\public\SNA\snarlt.h">
</File>
<File
RelativePath="..\..\public\SNA\snasnd.h">
</File>
<File
RelativePath="..\..\public\SNA\snasyn.h">
</File>
<File
RelativePath="..\..\public\SNA\snavig.h">
</File>
</Filter>
<File
RelativePath="Sna.mak">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -0,0 +1,5 @@
SCC = This is a source code control file
[SNA.vcproj]
SCC_Aux_Path = "P4SCC#srvperforce-ma:1666##raymandata##Editor"
SCC_Project_Name = Perforce Project

View File

@@ -0,0 +1,613 @@
/*=========================================================================
* SnaFile.c : Manage files with checksums and basic encryption.
*
* The checksum is a simple xor check.
* To use files w/ checksums you must open, close, read and write to a file
* using SNA_fn_bFOpen, SNA_fn_bFClose, etc.
*
* The functions automatically compute the checksum and/or crypt the datas upon reading or writing.
*
* How to create a file :
* Open it with SNA_fn_bFOpen (specify if you want to use checksum and/or encryption)
* Write data with SNA_fn_ulFWrite (you may call for it several times)
* When ALL datas are written, call SNA_fn_bWriteChecksum,
* then SNA_fn_bFClose
*
*
* How to read a file :
* Open it with SNA_fn_bFOpen
* Read data with SNA_fn_ulFRead (you may call for it several times)
* When ALL datas are read, call SNA_fn_bReadChecksum,
* then SNA_fn_bFClose
* Now, you can check if checksum is good with SNA_fn_bTestChecksum.
*
* You can put several checksums in one file.
* Simply call SNA_fn_bWriteChecksum when you want to add a checksum
* for datas allready written.
* Checksums only control datas written BETWEEN two consecutive SNA_fn_bWriteChecksum.
* Be sure to read checksums at the same place you wrote them.
*
* Do NOT use fseek when writing or reading, it would make the checksum useless.
* You can use other file functions like ftell like this: ftell( stSNAFile->p_xFile );
*
* Version 1.0
* Creation date 25/09/98
* Revision date
*
* (c) Ubi R&D 1998
*=========================================================================
*/
#define min(a, b) (((a) < (b)) ? (a) : (b))
#include <stdio.h>
#include <memory.h>
#include <string.h>
//#include "acp_opfi.h"
#include "snafile.h"
#include "TMP.h"
#include "mmg.h"
#include "snammg.h"
#include "snarlt.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* SNA_fn_vSetXorCode
* Sets the xor key for encryption of a file.
* To call after SNA_fn_bFOpen(..).
*/
void SNA_fn_vSetCryptKey( unsigned char _ulCryptKey, struct SNA_tdstFile_ *_p_stFile )
{
_p_stFile->ulCryptKey = _ulCryptKey;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* SNA_fn_vResetChecksum
* Sets the checksum of a file to 0.
* To use after reading and testing it's value, before further reading.
*/
void SNA_fn_vResetChecksum( struct SNA_tdstFile_ *_p_stFile )
{
_p_stFile->ulChecksum = 0;
_p_stFile->ucBytesInChecksumBuffer = 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* SNA_fn_bTestChecksum
* Tests if checksum is ok (==0).
* Tu use JUST AFTER SNA_bReadChecksum
*/
ACP_tdxBool SNA_fn_bTestChecksum( struct SNA_tdstFile_ *_p_stFile )
{
return (_p_stFile->ulChecksum == 0);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* SNA_fn_bWriteChecksum
* Write the computed checksum in the file.
* The written checksum checks datas between the current position and
* the beginning of the file or the position of the last call to SNA_fn_bWriteChecksum
*/
ACP_tdxBool SNA_fn_bWriteChecksum( struct SNA_tdstFile_ *_p_stFile )
{
if( SNA_fn_bFileUseChecksum( _p_stFile ) )
{
unsigned long ulTempChecksum = _p_stFile->ulChecksum;
DWORD dwlNumberOfBytesWriten;
if( _p_stFile->ucBytesInChecksumBuffer )
{
memset( &_p_stFile->a4_cChecksumBuffer[_p_stFile->ucBytesInChecksumBuffer], 4-_p_stFile->ucBytesInChecksumBuffer, 0 );
ulTempChecksum ^= *(unsigned long *)_p_stFile->a4_cChecksumBuffer;
_p_stFile->ucBytesInChecksumBuffer = 0;
}
_p_stFile->ulChecksum = 0;
SNA_M_WRITEFILE(_p_stFile->hFile , &ulTempChecksum , sizeof(ulTempChecksum) , &dwlNumberOfBytesWriten , NULL);
return (dwlNumberOfBytesWriten != 0);
}
return TRUE;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* Read file checksum (if file uses checksums)
* Return TRUE if checksum was read ok or FALSE if there was a read error.
* To test the checksum value, use SNA_fn_bTestChecksum
*/
ACP_tdxBool SNA_fn_bReadChecksum( struct SNA_tdstFile_ *_p_stFile )
{
if( SNA_fn_bFileUseChecksum( _p_stFile ) )
{
DWORD dwNbRead;
unsigned long ulTempChecksum = 0;
if( _p_stFile->ucBytesInChecksumBuffer )
{
memset( &_p_stFile->a4_cChecksumBuffer[_p_stFile->ucBytesInChecksumBuffer], 4-_p_stFile->ucBytesInChecksumBuffer, 0 );
_p_stFile->ulChecksum ^= *(unsigned long *)_p_stFile->a4_cChecksumBuffer;
_p_stFile->ucBytesInChecksumBuffer = 0;
}
if (!SNA_M_READFILE(_p_stFile->hFile , &ulTempChecksum , sizeof(ulTempChecksum) , &dwNbRead , NULL))
{
_p_stFile->ulChecksum = -1;
_p_stFile -> bReadSuccess = FALSE;
return FALSE;
}
_p_stFile -> bReadSuccess = TRUE;
_p_stFile->ulChecksum ^= ulTempChecksum;
}
return TRUE;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* Opens a file.
* ucOptions are a bitwise combo of SNA_C_ucUseChecksum and/or SNA_C_ucUseEncryption and/or SNA_C_ucUseMemBuffer
*/
void SNA_fn_vInitFile(unsigned char ucOptions, struct SNA_tdstFile_ *_p_stFile )
{
_p_stFile->ulChecksum = 0;
_p_stFile->ucBytesInChecksumBuffer = 0;
_p_stFile->ucOptions = ucOptions;
_p_stFile->p_fn_bWriteWithoutOptions = SNA_fn_bWriteToFile;
_p_stFile->p_fn_bReadWithoutOptions = SNA_fn_bReadFromFile;
if( SNA_fn_bFileUseEncryption( _p_stFile ) )
{
_p_stFile->ulCryptKey = 0x6AB5CC79; // Set default encryption key.
_p_stFile->p_fn_bDefaultWrite = SNA_fn_bCryptAndWriteToFile;
_p_stFile->p_fn_bDefaultRead = SNA_fn_bReadAndDecryptFromFile;
}
else
{
_p_stFile->ulCryptKey = 0;
_p_stFile->p_fn_bDefaultWrite = SNA_fn_bWriteToFile;
_p_stFile->p_fn_bDefaultRead = SNA_fn_bReadFromFile;
}
}
ACP_tdxBool SNA_fn_bFOpen(
char *_p_szfilename,
unsigned char ucMode,
unsigned char ucOptions,
struct SNA_tdstFile_ *_p_stFile )
{
DWORD dwCreate,dwAccess;
/*
_p_stFile->ulChecksum = 0;
_p_stFile->ucBytesInChecksumBuffer = 0;
_p_stFile->ucOptions = ucOptions;
_p_stFile->p_fn_bWriteWithoutOptions = SNA_fn_bWriteToFile;
_p_stFile->p_fn_bReadWithoutOptions = SNA_fn_bReadFromFile;
if( SNA_fn_bFileUseEncryption( _p_stFile ) )
{
_p_stFile->ulCryptKey = 0x6AB5CC79; // Set default encryption key.
_p_stFile->p_fn_bDefaultWrite = SNA_fn_bCryptAndWriteToFile;
_p_stFile->p_fn_bDefaultRead = SNA_fn_bReadAndDecryptFromFile;
}
else
{
_p_stFile->ulCryptKey = 0;
_p_stFile->p_fn_bDefaultWrite = SNA_fn_bWriteToFile;
_p_stFile->p_fn_bDefaultRead = SNA_fn_bReadFromFile;
}
*/
SNA_fn_vInitFile (ucOptions , _p_stFile);
switch(ucMode)
{
case SNA_C_ucWrite: dwCreate = CREATE_ALWAYS; dwAccess = GENERIC_WRITE;
{
DWORD dwAttrib = GetFileAttributes(_p_szfilename);
if(dwAttrib & FILE_ATTRIBUTE_READONLY)
SetFileAttributes(_p_szfilename , dwAttrib & ~FILE_ATTRIBUTE_READONLY);
}
break;
case SNA_C_ucRead: dwCreate = OPEN_EXISTING; dwAccess = GENERIC_READ; break;
default:
_asm {int 3h};
break;
}
_p_stFile -> hFile = SNA_M_CREATEFILE(_p_szfilename , dwAccess , 0 , NULL , dwCreate , FILE_ATTRIBUTE_NORMAL , NULL);
_p_stFile -> bReadSuccess = (_p_stFile -> hFile != INVALID_HANDLE_VALUE);
return (_p_stFile -> bReadSuccess);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* Closes a file
* Be sure to call SNA_fn_bTestChecksum before Close to check the value of the file checksum.
*/
ACP_tdxBool SNA_fn_bFClose( struct SNA_tdstFile_ *_p_stFile )
{
int iRes;
// _p_stFile->ulChecksum = 0;
_p_stFile->ucBytesInChecksumBuffer = 0;
iRes = (int) SNA_M_CLOSEHANDLE(_p_stFile->hFile);
_p_stFile->hFile = INVALID_HANDLE_VALUE;
return (iRes == 0);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* SNA_fn_ulFWrite
* Write datas into a file with or without encryption and checksum.
* (it checks the option field in SNA_tdstFile)
* Returns the number of items written.
*/
size_t SNA_fn_ulFWrite( void *_p_vBuffer, size_t _ulSize, size_t _ulCount, struct SNA_tdstFile_ *_p_stFile )
{
unsigned long ulTotalSize = _ulSize*_ulCount;
// If nothing to write, then nothing to do...
if( ! ulTotalSize ) return 0;
// Check if this file uses checksums.
if( SNA_fn_bFileUseChecksum( _p_stFile ) )
{
/* It uses checksums. */
unsigned char ucRest;
char *p_cBuffer = _p_vBuffer;
// If there was some bytes remaining in the checksum buffer, take them into account.
if( _p_stFile->ucBytesInChecksumBuffer )
{
// First, fill the buffer.
unsigned char ucBytesToCopy = (unsigned char)min( ulTotalSize, (unsigned long)(4-_p_stFile->ucBytesInChecksumBuffer) );
memcpy( &_p_stFile->a4_cChecksumBuffer[_p_stFile->ucBytesInChecksumBuffer], p_cBuffer, ulTotalSize );
// Update buffer info
_p_stFile->ucBytesInChecksumBuffer += ucBytesToCopy;
p_cBuffer += ucBytesToCopy;
ulTotalSize -= ucBytesToCopy;
// If buffer is full, compute checksum.
if( _p_stFile->ucBytesInChecksumBuffer == 4 )
{
_p_stFile->ulChecksum ^= *(unsigned long *)_p_stFile->a4_cChecksumBuffer;
_p_stFile->ucBytesInChecksumBuffer = 0;
}
}
// Compute number of long integers in the datas.
ucRest = (unsigned char)(ulTotalSize & 0x03); // =Total Size % 4
ulTotalSize >>= 2;
// For each long integer, update the checksum.
while( ulTotalSize )
{
_p_stFile->ulChecksum ^= *(unsigned long *)p_cBuffer;
p_cBuffer += 4;
ulTotalSize--;
}
// Trailing bytes (less than 4 bytes) are put in the checksum buffer.
if( ucRest )
{
memcpy( &_p_stFile->a4_cChecksumBuffer[_p_stFile->ucBytesInChecksumBuffer], p_cBuffer, ucRest );
_p_stFile->ucBytesInChecksumBuffer += ucRest;
}
} // end of checksum calculation
// Then, write the data to the file.
if( ! _p_stFile->p_fn_bDefaultWrite( _p_vBuffer, ulTotalSize, _p_stFile ) )
return 0;
return _ulCount;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/**
* SNA_fn_ulFRead
* Read datas from a file with or without encryption and checksum.
* (it checks the option field in SNA_tdstFile)
* Returns the number of items read.
*/
size_t SNA_fn_ulFRead( void *_p_vBuffer, size_t _ulSize, size_t _ulCount, struct SNA_tdstFile_ *_p_stFile )
{
unsigned long ulTotalSize = _ulSize*_ulCount;
// If nothing to read, then nothing to do...
if( ! ulTotalSize ) return 0;
// First, read the datas.
if( ! _p_stFile->p_fn_bDefaultRead( _p_vBuffer, ulTotalSize, _p_stFile ) )
return 0;
// Check if this file uses checksums.
if( SNA_fn_bFileUseChecksum( _p_stFile ) )
{
unsigned long ulTotalSize = _ulSize*_ulCount;
unsigned char ucRest;
char *p_cBuffer = _p_vBuffer;
if( _p_stFile->ucBytesInChecksumBuffer )
{
unsigned char ucBytesToCopy = (unsigned char)min( ulTotalSize, (unsigned long)(4-_p_stFile->ucBytesInChecksumBuffer) );
memcpy( &_p_stFile->a4_cChecksumBuffer[_p_stFile->ucBytesInChecksumBuffer], p_cBuffer, ucBytesToCopy );
_p_stFile->ucBytesInChecksumBuffer += ucBytesToCopy;
p_cBuffer += ucBytesToCopy;
ulTotalSize -= ucBytesToCopy;
if( _p_stFile->ucBytesInChecksumBuffer == 4 )
{
_p_stFile->ulChecksum ^= *(unsigned long *)_p_stFile->a4_cChecksumBuffer;
_p_stFile->ucBytesInChecksumBuffer = 0;
}
}
ucRest = (unsigned char)(ulTotalSize & 0x03); // =Total Size % 4
ulTotalSize >>= 2;
while( ulTotalSize )
{
_p_stFile->ulChecksum ^= *(unsigned long *)p_cBuffer;
p_cBuffer += 4;
ulTotalSize--;
}
if( ucRest )
{
memcpy( &_p_stFile->a4_cChecksumBuffer[_p_stFile->ucBytesInChecksumBuffer], p_cBuffer, ucRest );
_p_stFile->ucBytesInChecksumBuffer += ucRest;
}
} // End of checksum calculation
return _ulCount;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// For writing datas without encryption nor checksum calculation,
// even if the file has been opened with such options
size_t SNA_fn_ulFWriteWithoutOptions( void *_p_vBuffer, size_t _ulSize, size_t _ulCount, struct SNA_tdstFile_ *_p_stFile )
{
unsigned long ulTotalSize = _ulSize*_ulCount;
// If nothing to write, then nothing to do...
if( ! ulTotalSize ) return 0;
// write the data to the file without encryption nor checksum calculation
if( ! _p_stFile->p_fn_bWriteWithoutOptions( _p_vBuffer, ulTotalSize, _p_stFile ) )
return 0;
return _ulCount;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// For reading datas without encryption nor checksum calculation,
// even if the file has been opened with such options
// Use this function ONLY if you have written the datas you want to read
// with SNA_fn_ulFWriteWithoutOptions
size_t SNA_fn_ulFReadWithoutOptions( void *_p_vBuffer, size_t _ulSize, size_t _ulCount, struct SNA_tdstFile_ *_p_stFile )
{
unsigned long ulTotalSize = _ulSize*_ulCount;
// If nothing to read, then nothing to do...
if( ! ulTotalSize ) return 0;
// read the datas without encryption nor checksum calculation.
if( ! _p_stFile->p_fn_bReadWithoutOptions( _p_vBuffer, ulTotalSize, _p_stFile ) )
return 0;
return _ulCount;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ACP_tdxBool SNA_fn_bFileUseChecksum( struct SNA_tdstFile_ *_p_stFile )
{
return (_p_stFile->ucOptions & SNA_C_ucUseChecksum) != 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ACP_tdxBool SNA_fn_bFileUseEncryption( struct SNA_tdstFile_ *_p_stFile )
{
return (_p_stFile->ucOptions & SNA_C_ucUseEncryption) != 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
///////
// Handle seek for sna file.
// WARNING : you'd better not use seek with file with checksum and encryption.
// Encryption is handled by seek only if the origin is the current position.
// Checksum calculation is NOT handled by seek.
// This function does not check the validity of the offset.
// A bad offset (seek goes out of file) can cause problems in key calculation for files with encryption...
int SNA_fn_bFseek( struct SNA_tdstFile_ *_p_stFile, long _lOffset, int _lOrigin )
{
// fflush( _p_stFile->p_xFile );
DWORD dwMoveMethod;
if( _lOrigin == SEEK_CUR && SNA_fn_bFileUseEncryption( _p_stFile ) )
{
unsigned char *p_a_ucCryptKeys = (unsigned char *)&_p_stFile->ulCryptKey;
unsigned long ulOffset = abs( _lOffset );
ACP_tdxBool ucForward = (_lOffset>0);
if( _lOffset>0 )
while( ulOffset-- )
{
p_a_ucCryptKeys[0] += p_a_ucCryptKeys[2];
p_a_ucCryptKeys[1] += p_a_ucCryptKeys[3];
}
else
while( ulOffset-- )
{
p_a_ucCryptKeys[0] -= p_a_ucCryptKeys[2];
p_a_ucCryptKeys[1] -= p_a_ucCryptKeys[3];
}
}
if (_lOrigin == SEEK_SET) dwMoveMethod = FILE_BEGIN;
else if (_lOrigin == SEEK_END) dwMoveMethod = FILE_END;
else dwMoveMethod = FILE_CURRENT;
return SNA_M_SETFILEPOINTER(_p_stFile->hFile , _lOffset , NULL , dwMoveMethod);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
int SNA_fn_iFFlush( struct SNA_tdstFile_ *_p_stFile )
{
return (int) SNA_M_FLUSHFILEBUFFERS (_p_stFile->hFile);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Crypt the input data into the file.
// Return FALSE if an IO error occured
// To perform this, the datas to be written are copied into a buffer with encryption.
// Then the buffer is written to the file.
// Datas are cut into 2048 bytes blocs.
ACP_tdxBool SNA_fn_bCryptAndWriteToFile( const void *_p_vData, unsigned long _ulSize, struct SNA_tdstFile_ *_p_stFile )
{
unsigned char a_ucBuffer[2048];
unsigned long ulBytesInBuffer;
const unsigned char *p_ucInput, *p_ucEndInput, *p_ucEndStep;
unsigned char *p_ucOutput;
unsigned char *p_a_ucCryptKeys = (unsigned char *)&_p_stFile->ulCryptKey;
unsigned long ulBytesWritten;
// Compute the begining and the end of the input buffer (=datas to be written).
p_ucInput = _p_vData;
p_ucEndInput = (char *)_p_vData + _ulSize;
// For each 2048 bytes block.
do
{
// Compute amount of data to copy to the buffer (max 2048)
ulBytesInBuffer = p_ucEndInput - p_ucInput;
if( ulBytesInBuffer > 2048 ) ulBytesInBuffer = 2048;
// Compute the pointer to the end of this bloc.
p_ucEndStep = p_ucInput + ulBytesInBuffer;
// Destination = buffer.
p_ucOutput = a_ucBuffer;
// Perform the copy with encryption.
while( p_ucInput < p_ucEndStep )
{
/*
*p_ucOutput++ = (*p_ucInput++ ^ p_a_ucCryptKeys[1]) + p_a_ucCryptKeys[0];
p_a_ucCryptKeys[0] += p_a_ucCryptKeys[2];
p_a_ucCryptKeys[1] += p_a_ucCryptKeys[3];
*/
*p_ucOutput++ = (*p_ucInput++ ^ p_a_ucCryptKeys[1]);
*((DWORD*)p_a_ucCryptKeys) = SNA_fn_dwGetCryptKey(*((DWORD*)p_a_ucCryptKeys));
}
// Writes the buffer to disk.
SNA_M_WRITEFILE(_p_stFile->hFile , a_ucBuffer , ulBytesInBuffer , &ulBytesWritten, NULL);
// If not all datas were written (because of an error), we return FALSE.
if( ulBytesWritten != ulBytesInBuffer )
{
return FALSE;
}
// If not end of input, go for the next bloc.
} while( p_ucInput < p_ucEndInput );
// all the datas were written ok, return TRUE.
return TRUE;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Write the input data into file without encryption.
// Return FALSE if an IO error occured
ACP_tdxBool SNA_fn_bWriteToFile( const void *_p_vData, unsigned long _ulSize, struct SNA_tdstFile_ *_p_stFile )
{
DWORD dwBytesWritten;
SNA_M_WRITEFILE(_p_stFile->hFile , _p_vData , _ulSize , &dwBytesWritten, NULL);
return (dwBytesWritten == _ulSize);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Read the data from the IO buffer and decrypt it.
// Buffer is filled if needed
// Return FALSE if an IO error occured
ACP_tdxBool SNA_fn_bReadAndDecryptFromFile( void *_p_vData, unsigned long _ulSize, struct SNA_tdstFile_ *_p_stFile )
{
unsigned char *p_ucBuffer = _p_vData;
unsigned char *p_ucEndBuffer = p_ucBuffer + _ulSize;
unsigned char *p_a_ucCryptKeys = (unsigned char *)&_p_stFile->ulCryptKey;
// First, read the datas.
DWORD dwBytesRead;
_p_stFile -> bReadSuccess = SNA_M_READFILE(_p_stFile->hFile , p_ucBuffer , _ulSize , &dwBytesRead , NULL);
if( dwBytesRead != _ulSize )
return FALSE;
// Then, decrypt the datas.
for( ; p_ucBuffer<p_ucEndBuffer; p_ucBuffer++ )
{
/*
*p_ucBuffer = (*p_ucBuffer - p_a_ucCryptKeys[0]) ^ p_a_ucCryptKeys[1];
p_a_ucCryptKeys[0] += p_a_ucCryptKeys[2];
p_a_ucCryptKeys[1] += p_a_ucCryptKeys[3];
*/
*p_ucBuffer = (*p_ucBuffer ^ p_a_ucCryptKeys[1]);
*((DWORD*)p_a_ucCryptKeys) = SNA_fn_dwGetCryptKey(*((DWORD*)p_a_ucCryptKeys));
}
return TRUE;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Read the input data from file without encryption.
// Return FALSE if an IO error occured
ACP_tdxBool SNA_fn_bReadFromFile( void *_p_vData, unsigned long _ulSize, struct SNA_tdstFile_ *_p_stFile )
{
DWORD dwBytesRead;
_p_stFile -> bReadSuccess = SNA_M_READFILE(_p_stFile->hFile , _p_vData , _ulSize , &dwBytesRead , NULL);
return (dwBytesRead == _ulSize);
}

View File

@@ -0,0 +1,51 @@
#include "string.h"
#include "acp_base.h"
#include "cpa_expt.h"
#include "sna/snaglob.h"
extern ACP_tdxBool MMG_g_bResetMemOnAllocation;
unsigned char g_ucMemorySnapshot;
char g_szLevelName[255];
ACP_tdxBool g_bUsesBigFile;
/*
0 : Load Script files
1 : load binary data
2 : Save binary data
*/
void SNA_fn_vSetLoadType(unsigned char ucType)
{
g_ucMemorySnapshot=ucType;
if( ucType == SNA_SAVE_SNAPSHOT )
MMG_g_bResetMemOnAllocation = TRUE;
}
unsigned char SNA_fn_ucGetLoadType()
{
return g_ucMemorySnapshot;
}
void SNA_fn_vSetLevelName(char *szLevelName)
{
strcpy(g_szLevelName,szLevelName);
}
char *SNA_fn_ucGetLevelName()
{
return g_szLevelName;
}
void SNA_fn_vSetBigFile(ACP_tdxBool _bFigFileUsed)
{
g_bUsesBigFile = _bFigFileUsed;
}
ACP_tdxBool SNA_fn_bBigFileUsed()
{
return g_bUsesBigFile;
}

View File

@@ -0,0 +1,646 @@
/*=========================================================================
* Snammg.c : Save & Read the memory blocks
*
* Version 1.0
* Creation date 03/09/97
* Revision date
*
* (c) Ubi R&D 1997
*=======================================================================*/
#include "MMG.h"
#include "ToolsCPA.h"
#include "SNA.h"
#include "snafile.h"
#include "windows.h"
#include "acp_opfi.h"
// This define allows the encryption of the .sna files.
// Comment it for no encryption.
#define SNA_ENCRYPTION
ACP_tdxBool g_a_bIsBlocRelocated[C_ucNbOfMaxModule][10];
long g_a_ulOffset[C_ucNbOfMaxModule][10];
extern unsigned char g_ucGameModuleId;
extern unsigned char g_ucAIModuleId;
extern unsigned char g_ucGEOModuleId;
extern unsigned char g_ucIPTModuleId;
extern unsigned char g_ucFONModuleId;
extern unsigned char g_ucTMPModuleId;
extern unsigned char g_ucSndModuleId;
// Memory blocks that are saved for each level.
// Ex: (Game,0) => Block 0 of module Game.
struct tdstModuleBloc_ g_a_stModuleBlocToSaveInLevel[] =
{
SNA_M_SetBlocForSaving( Game, 1 ),
SNA_M_SetBlocForSaving( GEO, 2 ),
SNA_M_SetBlocForSaving( AI, 1 )
};
// Memory blocks that are saved in the fix.
struct tdstModuleBloc_ g_a_stModuleBlocToSaveInFix[] =
{
SNA_M_SetBlocForSaving( Game, 0 ),
SNA_M_SetBlocForSaving( GEO, 0 ),
SNA_M_SetBlocForSaving( GEO, 1 ),
SNA_M_SetBlocForSaving( IPT, 0 ),
SNA_M_SetBlocForSaving( AI, 0 ),
SNA_M_SetBlocForSaving( FON, 0 )
};
// Memory blocks that are NOT saved, but some infos will be included for relocation purpose.
// Actually, pointers from other blocks to these blocks will be correctly relocated.
// (except for TMP block: pointers to TMP will be set to NULL at load time)
struct tdstModuleBloc_ g_a_stModuleBlocToSaveInfos[] =
{
SNA_M_SetBlocForSaving( TMP, 0 ),
SNA_M_SetBlocForSaving( Snd, 0 )
};
unsigned long SNA_g_ulNbBlocksInFix = SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInFix);
unsigned long SNA_g_ulNbBlocksInLevel = SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInLevel);
char g_bSaveLoadFix;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Sort an array of blocks so that blocks are sorted by module and block number.
// An old good bubble sort :-)
void SNA_fn_vSortAnArray( struct tdstModuleBloc_ *_p_stArray, unsigned long _ulArraySize )
{
struct tdstModuleBloc_ *p_stArray2;
struct tdstModuleBloc_ *p_stLastElement = _p_stArray + _ulArraySize-1;
struct tdstModuleBloc_ *p_stEndOfArray = p_stLastElement + 1;
struct tdstModuleBloc_ stTmp;
for( ; _p_stArray < p_stLastElement; _p_stArray++ )
for( p_stArray2 = _p_stArray+1; p_stArray2 < p_stEndOfArray; p_stArray2++ )
if( (*(_p_stArray->p_ucModuleId) > *(p_stArray2->p_ucModuleId))
|| ( (*(_p_stArray->p_ucModuleId) == *(p_stArray2->p_ucModuleId))
&& (_p_stArray->ucBlockId > p_stArray2->ucBlockId) ) )
{
memcpy( &stTmp, _p_stArray, sizeof(struct tdstModuleBloc_) );
memcpy( _p_stArray, p_stArray2, sizeof(struct tdstModuleBloc_) );
memcpy( p_stArray2, &stTmp, sizeof(struct tdstModuleBloc_) );
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
void SNA_fn_vSetSaveLoadFix()
{
g_bSaveLoadFix=TRUE;
}
void SNA_fn_vSetSaveLoadLevel()
{
g_bSaveLoadFix=FALSE;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Tells if the bloc is to be loaded.
// Assumes that arrays of block are SORTED by module and block.
BOOL SNA_fn_bLoadThisModuleBloc( unsigned char _ucModule, unsigned char _ucBlock )
{
struct tdstModuleBloc_ *p_stArray, *p_stEndArray;
// Test Fix array when we load the fix or level array when we load the level
if( g_bSaveLoadFix )
{
p_stArray = g_a_stModuleBlocToSaveInFix;
p_stEndArray = p_stArray+SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInFix);
}
else
{
p_stArray = g_a_stModuleBlocToSaveInLevel;
p_stEndArray = p_stArray+SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInLevel);
}
// Go to the first block that have the module number "_ucModule"
while( p_stArray < p_stEndArray
&& _ucModule > *(p_stArray->p_ucModuleId) )
p_stArray ++;
// If we find one block with the good module ID, find the one with the good block ID.
if( p_stArray<p_stEndArray )
while( p_stArray < p_stEndArray
&& _ucModule == *(p_stArray->p_ucModuleId) )
{
if( _ucBlock == p_stArray->ucBlockId )
// Found one, return TRUE
return TRUE;
p_stArray ++;
}
// Block was not found in array, return FALSE
return FALSE;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Initialise the global arrays that hold the block to save and load.
// Basically, that means sorting them by module ID and block ID.
// The sorting needs to be done only once.
void SNA_fn_vInitArrays()
{
static ucArrayAreSorted = 0;
if( ! ucArrayAreSorted )
{
SNA_fn_vSortAnArray(g_a_stModuleBlocToSaveInFix, SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInFix) );
SNA_fn_vSortAnArray(g_a_stModuleBlocToSaveInLevel, SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInLevel) );
SNA_fn_vSortAnArray(g_a_stModuleBlocToSaveInfos, SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInfos) );
ucArrayAreSorted = 1;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Write the MMG header of each block in the given array to file.
//
// Input:
// _p_stArrayToSaveInfos : an array of block (ie: g_a_stModuleBlocToSaveInFix, etc)
// _ulNbElem : Number of elements in the array
// _ucBlockType : Type of block in the array (SNA_C_ucBlockOfFix, SNA_C_ucBlockOfLevel or SNA_C_ucEmptyBlock)
// _p_stFile : An opened file to write the infos.
void SNA_fn_vWriteMemoryInfosOfArray(
struct tdstModuleBloc_ *_p_stArrayToSaveInfos, unsigned long _ulNbElem,
unsigned char _ucBlocType, struct SNA_tdstFile_ *_p_stFile )
{
unsigned char ucModule, ucBlock;
unsigned long ulBlockSize,ulBeginBlock,ulEndBlock,ulMaxMem;
tdstBlockInfo stBloc;
while( _ulNbElem-- )
{
ucModule = *(_p_stArrayToSaveInfos->p_ucModuleId);
ucBlock = _p_stArrayToSaveInfos->ucBlockId;
// Write block header : ModuleID, BlockID and type(fix, level or empty)
SNA_fn_ulFWrite( &ucModule, sizeof(unsigned char), 1, _p_stFile );
SNA_fn_ulFWrite( &ucBlock, sizeof(unsigned char), 1, _p_stFile );
SNA_fn_ulFWrite( &_ucBlocType, sizeof(unsigned char), 1, _p_stFile );
// Get current infos from MMG
Mmg_fn_vGiveInformationBlock( ucModule, ucBlock, &stBloc );
ulBeginBlock=(unsigned long)stBloc.p_cBeginBlock;
ulEndBlock=(unsigned long)stBloc.p_cEndBlock;
ulMaxMem=(unsigned long)stBloc.p_cMaxMem;
SNA_fn_ulFWrite( &ulBeginBlock, 4, 1, _p_stFile );
if( ulBeginBlock != (unsigned long)C_p_cBlockNotValidKey )
{
SNA_fn_ulFWrite( &ulEndBlock, 4, 1, _p_stFile );
SNA_fn_ulFWrite( &(stBloc.p_cFirstFree), 4, 1, _p_stFile );
SNA_fn_ulFWrite( &(stBloc.p_cMaxMem), 4, 1, _p_stFile );
// Write block size
ulBlockSize=0;
SNA_fn_ulFWrite( &ulBlockSize, 4, 1, _p_stFile );
}
// Go to next element of the array
_p_stArrayToSaveInfos++;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// Write the MMG header AND CONTENT of each block in the given array to file.
//
// Input:
// _p_stArrayToSaveInfos : an array of block (ie: g_a_stModuleBlocToSaveInFix, etc)
// _ulNbElem : Number of elements in the array
// _ucBlockType : Type of block in the array (SNA_C_ucBlockOfFix, SNA_C_ucBlockOfLevel or SNA_C_ucEmptyBlock)
// _p_stFile : An opened file to write the infos.
void SNA_fn_vWriteMemoryBlocksOfArray(
struct tdstModuleBloc_ *_p_stArrayToSaveInfos, unsigned long _ulNbElem,
unsigned char _ucBlocType, struct SNA_tdstFile_ *_p_stFile )
{
unsigned char ucModule, ucBlock;
unsigned long ulBlockSize,ulBeginBlock,ulEndBlock,ulMaxMem;
tdstBlockInfo stBloc;
while( _ulNbElem-- )
{
ucModule = *(_p_stArrayToSaveInfos->p_ucModuleId);
ucBlock = _p_stArrayToSaveInfos->ucBlockId;
// Write block header : ModuleID, BlockID and type(fix, level or empty)
SNA_fn_ulFWrite( &ucModule, sizeof(unsigned char), 1, _p_stFile );
SNA_fn_ulFWrite( &ucBlock, sizeof(unsigned char), 1, _p_stFile );
SNA_fn_ulFWrite( &_ucBlocType, sizeof(unsigned char), 1, _p_stFile );
Mmg_fn_vGiveInformationBlock( ucModule, ucBlock, &stBloc );
ulBeginBlock=(unsigned long)stBloc.p_cBeginBlock;
ulEndBlock=(unsigned long)stBloc.p_cEndBlock;
ulMaxMem=(unsigned long)stBloc.p_cMaxMem;
SNA_fn_ulFWrite( &ulBeginBlock, 4, 1, _p_stFile );
if( ulBeginBlock != (unsigned long)C_p_cBlockNotValidKey )
{
SNA_fn_ulFWrite( &ulEndBlock, 4, 1, _p_stFile );
SNA_fn_ulFWrite( &(stBloc.p_cFirstFree), 4, 1, _p_stFile );
SNA_fn_ulFWrite( &(stBloc.p_cMaxMem), 4, 1, _p_stFile );
// Write block size
ulBlockSize=ulMaxMem-ulBeginBlock+1+8; // 8 : Remain place bloc info
SNA_fn_ulFWrite( &ulBlockSize, 4, 1, _p_stFile );
// Write the block
SNA_fn_ulFWrite(stBloc.p_cBeginBlock,1,ulBlockSize,_p_stFile);
}
_p_stArrayToSaveInfos++;
}
}
/*-----------------------------------------------------------------------------
* Description : Write all memory blocks to file
*-----------------------------------------------------------------------------
* Input : None
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : 29/09/97 Modification Author : CGHT
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vWriteAllMemoryBlocks(char *szFilename)
{
struct SNA_tdstFile_ stSnaFile;
DWORD dwBytesWritten;
SNA_fn_vInitArrays();
#if defined(SNA_ENCRYPTION)
SNA_fn_bFOpen(szFilename,SNA_C_ucWrite,SNA_C_ucUseEncryption,&stSnaFile);
#else
SNA_fn_bFOpen(szFilename,SNA_C_ucWrite,0,&stSnaFile);
#endif
// Write crypt key in file
SNA_M_WRITEFILE(stSnaFile.hFile , &stSnaFile.ulCryptKey , sizeof(stSnaFile.ulCryptKey) , &dwBytesWritten, NULL);
// First, write some infos on some block witch content will not be saved (for pointer destination detection only)
SNA_fn_vWriteMemoryInfosOfArray(
g_a_stModuleBlocToSaveInfos, SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInfos),
SNA_C_ucEmptyBlock, &stSnaFile);
// Then write the infos about the blocks that will be saved
SNA_fn_vWriteMemoryInfosOfArray(
g_a_stModuleBlocToSaveInFix, SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInFix),
SNA_C_ucBlockOfFix, &stSnaFile );
if( g_bSaveLoadFix )
{
// In the fix sna file, write the content of all fix memory blocks
SNA_fn_vWriteMemoryBlocksOfArray(
g_a_stModuleBlocToSaveInFix, SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInFix),
SNA_C_ucBlockOfFix, &stSnaFile );
}
else
{
// In the level sna file, write the infos of the level mem blocks
SNA_fn_vWriteMemoryInfosOfArray(
g_a_stModuleBlocToSaveInLevel, SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInLevel),
SNA_C_ucBlockOfLevel, &stSnaFile );
// Then write the content of all level memory blocks
SNA_fn_vWriteMemoryBlocksOfArray(
g_a_stModuleBlocToSaveInLevel, SNA_M_NbElementOfBlocArray(g_a_stModuleBlocToSaveInLevel),
SNA_C_ucBlockOfLevel, &stSnaFile );
}
SNA_fn_bFClose(&stSnaFile);
}
/*-----------------------------------------------------------------------------
* Description : Read all memory blocks from file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
BOOL SNA_fn_bReadAllMemoryBlocks(char *szFilename)
{
struct SNA_tdstFile_ stFile;
ACP_tdxBool bOpenFileOK;
unsigned char ucModule,ucBlock;
unsigned long ulBlockSize,ulBeginBlock,ulEndBlock,ulFirstFree,ulMaxMem;
unsigned long p_vPtr,*p_ulPtr;
unsigned long i,j,k;
unsigned char ucTargetModule, ucTargetBloc;
tdstBlockInfo stBloc;
unsigned long ulNbReloc = 0;
DWORD dwBytesRead;
#ifndef RETAIL
char szText[150];
unsigned long ulNbPointerToUnknown = 0;
unsigned long ulNbPointerToTmp = 0;
#endif
// MR2711
SNA_fn_vInitArrays();
#if defined(SNA_ENCRYPTION)
ACP_M_OPENFILE(SNA_fn_bFOpen,bOpenFileOK,FALSE,szFilename,(szFilename,SNA_C_ucRead,SNA_C_ucUseEncryption,&stFile));
#else
ACP_M_OPENFILE(SNA_fn_bFOpen,bOpenFileOK,FALSE,szFilename,(szFilename,SNA_C_ucRead,0,&stFile));
#endif
if (! bOpenFileOK)
return FALSE;
stFile.bReadSuccess = SNA_M_READFILE(stFile.hFile , &stFile.ulCryptKey , sizeof(stFile.ulCryptKey) , &dwBytesRead , NULL);
#ifdef _DEBUG
// Set relocation infos to invalid values.
memset( g_a_bIsBlocRelocated, 55, C_ucNbOfMaxModule*10 );
#endif
/// Load Reloc Table
SNA_M_LoadUsedRelocationTable();
// Take care of the progress bar
VIG_fn_vAddToProgressBar(1);
// Begin read from SNA file.
while(stFile.bReadSuccess)
{
// Read Module ID and Block ID
i=SNA_fn_ulFRead(&ucModule,1,1,&stFile);
if(i==0)
{
break;
}
SNA_fn_ulFRead(&ucBlock,1,1,&stFile);
// Read block location (fix or level)
SNA_fn_ulFRead(&i,1,1,&stFile);
// Get current info on this block
Mmg_fn_vGiveInformationBlock(ucModule,ucBlock,&stBloc);
g_a_bIsBlocRelocated[ucModule][ucBlock]=FALSE;
// Read beginning of block
SNA_fn_ulFRead(&ulBeginBlock,4,1,&stFile);
// Test if block's emplacement has changed (=if it is relocated).
if(stBloc.p_cBeginBlock!=(char *)ulBeginBlock)
{
// If so, compute the offset between the old block and the new one.
g_a_bIsBlocRelocated[ucModule][ucBlock]=TRUE;
g_a_ulOffset[ucModule][ucBlock]=(long)stBloc.p_cBeginBlock-(long)ulBeginBlock;
#ifndef RETAIL
sprintf( szText, "Module %d Bloc %d is relocated from %lx to %lx\n", ucModule, ucBlock, ulBeginBlock, stBloc.p_cBeginBlock );
OutputDebugString(szText);
#endif
}
else
{
// If it's not relocated, offset=0
g_a_ulOffset[ucModule][ucBlock]=0;
}
// MR0310
if ((char *)ulBeginBlock==C_p_cBlockNotValidKey)
continue;
SNA_fn_ulFRead(&ulEndBlock,4,1,&stFile);
// If this block is to be loaded by sna, update some infos in MMG structures.
// (FirstFree and MaxMem)
SNA_fn_ulFRead(&ulFirstFree,4,1,&stFile);
SNA_fn_ulFRead(&ulMaxMem,4,1,&stFile);
SNA_fn_ulFRead(&ulBlockSize,4,1,&stFile);
if( SNA_fn_bLoadThisModuleBloc(ucModule,ucBlock) && ulBlockSize>0 )
{
stBloc.p_cMaxMem=(char *)ulMaxMem+g_a_ulOffset[ucModule][ucBlock];
if( ulFirstFree!= (unsigned long)C_p_cBlockNotValidKey )
stBloc.p_cFirstFree=(char *)ulFirstFree+g_a_ulOffset[ucModule][ucBlock];
// Read the block
SNA_fn_ulFRead(stBloc.p_cBeginBlock,1,ulBlockSize,&stFile);
// Save the updated memory block info for MMG.
Mmg_fn_vSaveInformationBlock(ucModule,ucBlock,&stBloc);
// Take care of the progress bar
VIG_fn_vAddToProgressBar(1);
// Now we are going to relocate each pointer in the current block.
// Search reloc info for current block.
for (k=0;k<SNA_g_PTCRelocationTable->ucBlocNumber;k++)
if ((SNA_g_PTCRelocationTable->p_stBloc[k].ucModuleNumber==ucModule) &&
(SNA_g_PTCRelocationTable->p_stBloc[k].ucBlocNumber==ucBlock))
{
break;
}
// If there are reloc infos,
if (k<SNA_g_PTCRelocationTable->ucBlocNumber)
{
// go throught the pointer table.
for (j=0;j<SNA_g_PTCRelocationTable->p_stBloc[k].ulSize;j++)
{
// For each pointer to be relocated,
// get his target module and block.
ucTargetModule=SNA_g_PTCRelocationTable->p_stBloc[k].p_stPtr[j].ucTargetModule;
ucTargetBloc=SNA_g_PTCRelocationTable->p_stBloc[k].p_stPtr[j].ucTargetBlock;
#ifdef _DEBUG
// Make sure the source and dest block infos have been read.
assert( g_a_bIsBlocRelocated[ucModule][ucBlock] != 55 );
if( ucTargetModule < 0xf0 )
assert( g_a_bIsBlocRelocated[ucTargetModule][ucTargetBloc] != 55 );
#endif
p_vPtr=g_a_bIsBlocRelocated[ucModule][ucBlock]?
SNA_g_PTCRelocationTable->p_stBloc[k].p_stPtr[j].p_vPtr+g_a_ulOffset[ucModule][ucBlock]:
SNA_g_PTCRelocationTable->p_stBloc[k].p_stPtr[j].p_vPtr;
p_ulPtr=(unsigned long *)p_vPtr;
if (ucTargetModule == g_ucTMPModuleId)
{
// If pointer points to TMP, set it to NULL.
(*p_ulPtr) = (unsigned long)NULL; // GuS (28/09/98)
#ifndef RETAIL
ulNbPointerToTmp ++;
#endif
}
else if (ucTargetModule==0xff)
{
// If that pointer point to an unknown place ... well... we let it do that !
#ifndef RETAIL
ulNbPointerToUnknown ++;
#endif
}
else
{
(*p_ulPtr) += g_a_ulOffset[ucTargetModule][ucTargetBloc];
}
}
// Take care of the progress bar
VIG_fn_vAddToProgressBar(1);
}
}
else if( ulBlockSize > 0 )
{
SNA_fn_bFseek( &stFile, ulBlockSize, SEEK_CUR );
}
}
SNA_M_FreeRelocationTable();
SNA_fn_bFClose(&stFile);
#ifndef RETAIL
sprintf
( szText,
"Found %li pointers in %s that point to a TMP block.\n(Those pointers have been set to NULL)\n",
ulNbPointerToTmp, szFilename );
OutputDebugString( szText );
sprintf
( szText,
"Found %li pointers in %s that point to an unknown place.\n(Those pointers have not been relocated)\n",
ulNbPointerToUnknown, szFilename );
OutputDebugString( szText );
#endif
return TRUE;
}
#ifndef RETAIL
// For debug ONLY !
/*
fn_vChangeWindowTitle("Checking MMG blocks...");
//SNA_fn_vCheckAllMMGBlocks();
fn_vChangeWindowTitle("Rayman II");
static unsigned char ucDelay = 0;
if( ucDelay++ >= 30 )
{
fn_vChangeWindowTitle("Checking MMG blocks...");
//SNA_fn_vCheckAllMMGBlocks();
fn_vChangeWindowTitle("Rayman II");
ucDelay = 0;
}
*/
// Function for checking integrity of a mem block.
// Block must be static and with free.
// This function can detect errors caused by memory overwrites.
void SNA_fn_vCheckMMGBlock( unsigned char _ucModule, unsigned char _ucBlock, unsigned char _ucLog )
{
static unsigned long ulCallCount = 0;
struct tdstBlockInfo_ stInfoMMG;
long *p_lFree;
long *p_lAlloc;
long lSize, lNext;
long lNbFree, lNbAlloc, lTotalFree, lTotalAlloc;
char szFileName[255];
FILE *p_xFile;
lNbFree = lNbAlloc = lTotalFree = lTotalAlloc = 0;
Mmg_fn_vGiveInformationBlock( _ucModule, _ucBlock, &stInfoMMG );
// Can't check uninitialised block
if( stInfoMMG.p_cBeginBlock == (char *)0xffffffff )
return;
// Can't check block without free
if( stInfoMMG.p_cFirstFree == (char *)0xffffffff )
return;
p_lFree = (long *)stInfoMMG.p_cFirstFree;
p_lAlloc = (long *)stInfoMMG.p_cBeginBlock;
// FirstFree is out of block ?
if( p_lFree )
assert( (p_lFree >= (long *)(stInfoMMG.p_cBeginBlock)) && (p_lFree < (long *)(stInfoMMG.p_cEndBlock)) );
// BeginBlock is greater than EndOfBlock ?
assert( p_lAlloc < (long *)(stInfoMMG.p_cEndBlock) );
while( p_lAlloc < (long *)(stInfoMMG.p_cEndBlock) )
{
lSize = *p_lAlloc << C_uwShiftAllocSize >> 2;
// Size of allocated block is null or too big ?
assert( lSize > 0 );
// This is a free memory block.
if( p_lAlloc == p_lFree )
{
lNext = *(p_lFree+1);
// Size of free block is too big ?
assert( (p_lFree+lSize >= (long *)(stInfoMMG.p_cBeginBlock)) && (p_lFree+lSize < (long *)(stInfoMMG.p_cEndBlock+4)) );
if( lNext != 0 )
// Next free is out of Block bounds ?
assert( (lNext >= (long)(stInfoMMG.p_cBeginBlock)) && (lNext < (long)(stInfoMMG.p_cEndBlock)) );
p_lFree = (long *)lNext;
lNbFree++;
lTotalFree += lSize;
}
else
{
// Allocated mem block goes beyong it's bounds ?
if( p_lFree )
assert( p_lAlloc+lSize <= p_lFree );
// Allocated mem block size is too big ?
assert( (p_lAlloc+lSize >= (long *)(stInfoMMG.p_cBeginBlock)) && (p_lAlloc+lSize < (long *)(stInfoMMG.p_cEndBlock+4)) );
lNbAlloc++;
lTotalAlloc += lSize;
}
p_lAlloc += lSize;
}
if( _ucLog )
{
sprintf( szFileName, "Block%02x%02x.log", _ucModule, _ucBlock );
p_xFile = fopen( szFileName, "at" );
if( p_xFile )
{
ulCallCount++;
fprintf( p_xFile, "Block=#%02x%02x (Number=#%03d)\n", _ucModule, _ucBlock, ulCallCount );
fprintf( p_xFile, " Nb Alloc=%05d Total Allocated=%d\n", lNbAlloc, lTotalAlloc );
fprintf( p_xFile, " Nb Free=%05d Total Free=%d\n", lNbFree, lTotalFree );
fclose( p_xFile );
}
}
}
// Call CheckMMGBlock for each block.
void SNA_fn_vCheckAllMMGBlocks()
{
unsigned char i, j;
for( i=0; i<C_ucNbOfMaxModule; i++ )
for( j=0; j<g_a_ucBlocksNbInModule[i]; j++ )
SNA_fn_vCheckMMGBlock( i, j, 0 );
}
#endif // ! RETAIL

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,515 @@
/*=========================================================================
* Snapoint.c : Save & Read the sound pointers
*
* Version 1.0
* Creation date 03/09/97
* Revision date
*
* (c) Ubi R&D 1997
*=======================================================================*/
#include "ACP_Base.h"
#include "mmg.h"
#include "ToolsCPA.h"
#include "Actions/AllActs.h"
#include "structur/Objects.h"
#include "ObjType.h"
#include "SNA.h"
#include "acp_opfi.h"
#include "SNAfile.h"
struct SNA_tdstFixInfo_ SNA_g_stFixInfo =
{
NULL,NULL,NULL,NULL, 0,
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
};
HANDLE g_hPointersFile;
struct tdstPtr_ *g_p_stNextPtrRelocInfo; // Next pointer to use in pointer table relocation
struct tdstPtr_ *g_p_stAfterLastPtrRelocInfo; // Pointer after last pointer in pointer table relocation
/*-----------------------------------------------------------------------------
* Description : Open pointers file (write)
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_xWriteOpenGlobalPointersFile(char *szFileName)
{
DWORD dwAttrib = GetFileAttributes(szFileName);
SNA_fn_vInitArrays(); // MR2711
// CGHT 1612
if(dwAttrib & FILE_ATTRIBUTE_READONLY)
SetFileAttributes(szFileName , dwAttrib & ~FILE_ATTRIBUTE_READONLY);
ACP_M_OPENFILE(SNA_M_CREATEFILE,g_hPointersFile,INVALID_HANDLE_VALUE,szFileName,(szFileName , GENERIC_WRITE , 0 , NULL , CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL , NULL));
}
/*-----------------------------------------------------------------------------
* Description : Open pointers file (read)
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_xReadOpenGlobalPointersFile(char *szFileName)
{
SNA_fn_vInitArrays();
ACP_M_OPENFILE(SNA_M_CREATEFILE,g_hPointersFile,INVALID_HANDLE_VALUE,szFileName,(szFileName , GENERIC_READ , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL));
SNA_M_LoadUsedRelocationTable();
g_p_stNextPtrRelocInfo = &SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[0];
g_p_stAfterLastPtrRelocInfo = &SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[SNA_g_PTCRelocationTable->p_stBloc[0].ulSize];
// Take care of the progress bar
VIG_fn_vAddToProgressBar(1);
}
/*-----------------------------------------------------------------------------
* Description : Close pointers file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vCloseGlobalPointersFile()
{
SNA_M_FreeRelocationTable();
SNA_M_CLOSEHANDLE(g_hPointersFile);
// Take care of the progress bar
VIG_fn_vAddToProgressBar(1);
g_p_stNextPtrRelocInfo = g_p_stAfterLastPtrRelocInfo = NULL;
}
/*-----------------------------------------------------------------------------
* Description : Open Texture Relocation file (read)
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : CGHT
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_xReadOpenGlobalTextureFile()
{
SNA_M_LoadUsedRelocationTable();
g_p_stNextPtrRelocInfo = &SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[0];
g_p_stAfterLastPtrRelocInfo = &SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[SNA_g_PTCRelocationTable->p_stBloc[0].ulSize];
}
/*-----------------------------------------------------------------------------
* Description : Close Texture Relocation file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : CGHT
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vCloseGlobalTextureFile()
{
SNA_M_FreeRelocationTable();
g_p_stNextPtrRelocInfo = g_p_stAfterLastPtrRelocInfo = NULL;
}
/*-----------------------------------------------------------------------------
* Description : Write any block in file
*-----------------------------------------------------------------------------
* Input : Address and Size of block
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 09/02/99 Author : MT
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vWriteBlockInGlobalPointersFile(void *p_vAdr,unsigned long ulStructSize)
{
DWORD dwBytesWritten;
SNA_M_WRITEFILE(g_hPointersFile , p_vAdr, ulStructSize , &dwBytesWritten, NULL);
}
/*-----------------------------------------------------------------------------
* Description : Read any block in file
*-----------------------------------------------------------------------------
* Input : Address and Size of block
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 09/02/99 Author : MT
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vReadBlockInGlobalPointersFile(void *p_vAdr,unsigned long ulStructSize)
{
DWORD dwBytesRead;
SNA_M_READFILE(g_hPointersFile , p_vAdr, ulStructSize , &dwBytesRead, NULL);
}
/*-----------------------------------------------------------------------------
* Description : Write a pointer in file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vWritePointerInGlobalPointersFile(unsigned long ulPointerAdr)
{
SNA_fn_vWriteBlockInGlobalPointersFile(&ulPointerAdr,4);
}
void SNA_fn_vWriteStructureInGlobalPointersFile(void *p_vAdr,unsigned long ulStructSize)
{
SNA_fn_vWriteBlockInGlobalPointersFile(p_vAdr,ulStructSize);
// GuS (22/09/98) for 32 bits alignement.
if( (ulStructSize%4) != 0 )
{
char a3_cDummy[3];
memset( a3_cDummy, 0, 3 );
SNA_fn_vWriteBlockInGlobalPointersFile(a3_cDummy,4-(ulStructSize%4));
}
}
/*-----------------------------------------------------------------------------
* Description : Writes an array to global pointer file.
* This function makes sure that each element of the array is 32 bits aligned.
*-----------------------------------------------------------------------------
* Input : Base address of array, size of an element, number of elements
* Ex: struct tdstDummyStruct_ a24_stArray[24];
* SNA_fn_vWriteArrayInGlobalPointersFile
* ( a24_stArray, sizeof(struct tdstDummyStruct_), 24 );
*
* Output : None
* Remarks : Use this function if your array contains pointers.
* Otherwise, use SNA_fn_vWriteArrayWithoutPointerInGlobalPointersFile
*-----------------------------------------------------------------------------
* Creation date : 22/09/98 Author : Guillaume Souchet
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vWriteArrayInGlobalPointersFile
(
void *p_vAdr,
unsigned long ulNumberOfElements,
unsigned long ulElementSize
)
{
unsigned long ulRest; // Number of bytes to add for 32 bits align.
char a3_cDummy[3]; // Array of bytes to write for 32 bits align.
// Proceed only for element size > 0
if( ulElementSize == 0 ) return;
// Initialise variables
memset( a3_cDummy, 0, 3 );
if( (ulRest = (ulElementSize & 0x03)) != 0 )
ulRest = 4-ulRest;
// Write all elements.
while( ulNumberOfElements-- )
{
// Write one element and make it 32 bits aligned.
SNA_fn_vWriteBlockInGlobalPointersFile (p_vAdr , ulElementSize);
SNA_fn_vWriteBlockInGlobalPointersFile (a3_cDummy , ulRest);
// Go to next element.
p_vAdr = (void *)(((char *)p_vAdr)+ulElementSize);
}
}
/*-----------------------------------------------------------------------------
* Description : Function for writing an array *WITHOUT POINTERS* to global pointer file.
* This function don't care if all elements are 32 bits aligned.
*-----------------------------------------------------------------------------
* Input : Base address of array, size of an element, number of elements
* Ex: struct tdstDummyStruct_ a24_stArray[24];
* SNA_fn_vWriteArrayWithoutPointerInGlobalPointersFile(
* a24_stArray, sizeof(struct tdstDummyStruct_), 24 );
* Output : None
* Remark : Use this function if your array do *NOT* contains pointers.
Otherwise, use SNA_fn_vWriteArrayInGlobalPointersFile
*-----------------------------------------------------------------------------
* Creation date : 22/09/98 Author : Guillaume Souchet
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vWriteArrayWithoutPointerInGlobalPointersFile
(
void *p_vAdr,
unsigned long ulNumberOfElements,
unsigned long ulElementSize
)
{
unsigned long ulRest; // Number of bytes to add for 32 bits align.
char a3_cDummy[3]; // Array of bytes to write for 32 bits align.
unsigned long ulTotalSize = ulElementSize * ulNumberOfElements;
// Proceed only if there's something to write.
if( ulTotalSize == 0 ) return;
// Initialise variables
memset( a3_cDummy, 0, 3 );
if( (ulRest = (ulTotalSize & 0x03)) != 0 )
ulRest = 4-ulRest;
// Write all elements.
SNA_fn_vWriteBlockInGlobalPointersFile (p_vAdr , ulTotalSize);
// Write some bytes for 32 bits alignement
SNA_fn_vWriteBlockInGlobalPointersFile (a3_cDummy , ulRest);
}
/*-----------------------------------------------------------------------------
* Description : Read a pointer
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
unsigned long SNA_fn_vReadPointerFromGlobalPointersFile()
{
unsigned long ulOldAdrPointer;
SNA_fn_vReadBlockInGlobalPointersFile (&ulOldAdrPointer , 4);
if( g_p_stNextPtrRelocInfo < g_p_stAfterLastPtrRelocInfo
&& ulOldAdrPointer == g_p_stNextPtrRelocInfo->p_vPtr )
{
unsigned char ucModuleNumber = g_p_stNextPtrRelocInfo -> ucTargetModule;
unsigned char ucBlocNumber = g_p_stNextPtrRelocInfo -> ucTargetBlock;
if( g_a_bIsBlocRelocated[ucModuleNumber][ucBlocNumber] )
ulOldAdrPointer+=g_a_ulOffset[ucModuleNumber][ucBlocNumber];
g_p_stNextPtrRelocInfo++;
}
else
{
ulOldAdrPointer = ulOldAdrPointer;
}
return ulOldAdrPointer;
}
/*-----------------------------------------------------------------------------
* Description : Relocate Texture pointer
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : CGHT
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vRelocateTexturePointer(unsigned long **p_ulOldAdrPointer)
{
/* unsigned long ulSize;
struct tdstPtr_ *p_stPtrTemp, *p_stPtrEnd;
ulSize = SNA_g_PTCRelocationTable->p_stBloc[0].ulSize;
p_stPtrTemp = &SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[0];
p_stPtrEnd = &SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[ulSize];
while (p_stPtrTemp < p_stPtrEnd)
{
unsigned char ucModuleNumber,ucBlocNumber;
ucModuleNumber = p_stPtrTemp -> ucTargetModule;
ucBlocNumber = p_stPtrTemp -> ucTargetBlock;
if ((*(unsigned long *)p_ulOldAdrPointer==p_stPtrTemp->p_vPtr)&&(g_a_bIsBlocRelocated[ucModuleNumber][ucBlocNumber]))
{
((unsigned long)*p_ulOldAdrPointer)+=g_a_ulOffset[ucModuleNumber][ucBlocNumber];
break;
}
p_stPtrTemp ++;
}
*/
if( g_p_stNextPtrRelocInfo < g_p_stAfterLastPtrRelocInfo
&& *p_ulOldAdrPointer == (unsigned long *)g_p_stNextPtrRelocInfo->p_vPtr )
{
unsigned char ucModuleNumber = g_p_stNextPtrRelocInfo -> ucTargetModule;
unsigned char ucBlocNumber = g_p_stNextPtrRelocInfo -> ucTargetBlock;
if( g_a_bIsBlocRelocated[ucModuleNumber][ucBlocNumber] )
*(unsigned long *)p_ulOldAdrPointer += g_a_ulOffset[ucModuleNumber][ucBlocNumber];
g_p_stNextPtrRelocInfo++;
}
}
// -----------------------------------------------------
void SNA_fn_vReadStructureFromGlobalPointersFile(unsigned long *p_ulAdr,unsigned long ulStructSize)
{
// unsigned long i,j;
unsigned long *p_ulAdrTemp, *p_ulAdrEnd;
SNA_fn_vReadBlockInGlobalPointersFile (p_ulAdr , ulStructSize);
// Read trailing bytes for 32 bits alignement
if( (ulStructSize%4) != 0 )
{
char a3_cDummy[3];
SNA_fn_vReadBlockInGlobalPointersFile (a3_cDummy , 4-(ulStructSize%4));
}
p_ulAdrTemp = p_ulAdr;
ulStructSize>>=2;
p_ulAdrEnd = &p_ulAdr[ulStructSize];
while (p_ulAdrTemp < p_ulAdrEnd)
{
if( g_p_stNextPtrRelocInfo < g_p_stAfterLastPtrRelocInfo
&& *p_ulAdrTemp == g_p_stNextPtrRelocInfo->p_vPtr )
{
unsigned char ucModuleNumber = g_p_stNextPtrRelocInfo -> ucTargetModule;
unsigned char ucBlocNumber = g_p_stNextPtrRelocInfo -> ucTargetBlock;
if( g_a_bIsBlocRelocated[ucModuleNumber][ucBlocNumber] )
*p_ulAdrTemp += g_a_ulOffset[ucModuleNumber][ucBlocNumber];
g_p_stNextPtrRelocInfo++;
}
else
{
*p_ulAdrTemp = *p_ulAdrTemp;
}
p_ulAdrTemp ++;
}
}
// MR1311
void SNA_fn_vSimpleReadFromGlobalPointersFile(unsigned long *p_ulAdr,unsigned long ulStructSize)
{
SNA_fn_vReadBlockInGlobalPointersFile (p_ulAdr , ulStructSize);
}
/*-----------------------------------------------------------------------------
* Description : Reads an array from global pointer file.
*-----------------------------------------------------------------------------
* Input : Base address of array, size of an element, number of elements
* Ex: struct tdstDummyStruct_ a24_p_stArray[24];
* SNA_fn_vReadArrayFromGlobalPointersFile
* ( a24_p_stArray, sizeof(struct tdstDummyStruct_), 24 );
*
* Output : None
* Remarks : see SNA_fn_vWriteArrayInGlobalPointersFile
*-----------------------------------------------------------------------------
* Creation date : 22/09/98 Author : Guillaume Souchet
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vReadArrayFromGlobalPointersFile
(
void *p_vAdr,
unsigned long ulNumberOfElements,
unsigned long ulElementSize
)
{
// Proceed only for element size > 0
if( ulElementSize == 0 || ulNumberOfElements == 0 ) return;
// Read all elements.
while( ulNumberOfElements-- )
{
SNA_fn_vReadStructureFromGlobalPointersFile( p_vAdr, ulElementSize );
// Go to next element.
p_vAdr = (void *)(((char *)p_vAdr)+ulElementSize);
}
}
/*-----------------------------------------------------------------------------
* Description : Function for reading an array *CONTAINING NO POINTERS* from global pointer file.
*-----------------------------------------------------------------------------
* Input : Base address of array, size of an element, number of elements
* Ex: struct tdstDummyStruct_ a24_stArray[24];
* SNA_fn_vWriteArrayInGlobalPointersFile(
* a24_stArray, sizeof(struct tdstDummyStruct_), 24 );
* Output : None
* Remark : Use this function if your array do *NOT* contains pointers.
Otherwise, use SNA_fn_vWriteArrayInGlobalPointersFile
*-----------------------------------------------------------------------------
* Creation date : 22/09/98 Author : Guillaume Souchet
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vReadArrayWithoutPointerFromGlobalPointersFile
(
void *p_vAdr,
unsigned long ulNumberOfElements,
unsigned long ulElementSize
)
{
unsigned long ulRest; // Number of bytes to add for 32 bits align.
char a3_cDummy[3]; // Array of bytes to write for 32 bits align.
unsigned long ulTotalSize = ulElementSize * ulNumberOfElements;
// Proceed only if there's something to write.
if( ulTotalSize == 0 ) return;
// Initialise variables
memset( a3_cDummy, 0, 3 );
if( (ulRest = (ulTotalSize & 0x03)) != 0 )
ulRest = 4-ulRest;
// Read all elements.
SNA_fn_vReadBlockInGlobalPointersFile (p_vAdr , ulTotalSize);
SNA_fn_vReadBlockInGlobalPointersFile (a3_cDummy , ulRest);
}

View File

@@ -0,0 +1,632 @@
#include "ACP_Base.h"
#include "ToolsCPA.h"
#include "mmg.h"
#include "SNA.h"
#include "acp_opfi.h"
#include "SNAFile.h"
/* ANNECY OA - 13/07/99 { */
#define C_MAX_CONNECTED_FILES 20
char *a_BigFilesName[C_MAX_CONNECTED_FILES] = {
"LEVELS.DAT",
"MAP.DAT",
"TEXTURES.DAT",
"ANIMS.DAT",
"DATA01.DAT",
"DATA02.DAT",
"DATA03.DAT",
"DATA04.DAT",
"DATA05.DAT",
"DATA06.DAT"
"DATA07.DAT",
"DATA08.DAT",
"DATA09.DAT",
"DATA10.DAT",
"DATA11.DAT",
"DATA12.DAT",
"DATA13.DAT",
"DATA14.DAT",
"DATA15.DAT",
"DATA16.DAT",
};
/* END ANNECY OA } */
/*------------------------------------------------------------------------*/
#define SNA_M_OffSet_Error 0xFFFFFFFF
/*------------------------------------------------------------------------*/
unsigned char SNA_g_ucNextRelocationTableToLoad[4];
tdstRelocTable *SNA_g_PTCRelocationTable = NULL;
DWORD SNA_g_a_dwInitKeyRelocationTableLoaded[SNA_M_ProtectRelocationTableSize];
DWORD SNA_g_a_dwProtectKeyRelocationTableLoaded[SNA_M_ProtectRelocationTableSize];
DWORD SNA_g_dwNumberOfRelocationTableLoaded;
/*
*
*
*/
void SNA_fn_vInitBigFile();
ACP_tdxBool SNA_fn_bGetHandleToRelocationTableInBigFile( SNA_tdstFile *_p_stFile );
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
HANDLE SNA_fn_hGetOffSetInBigFileWithSinusHeader(DWORD *p_dwOffSet);
#define M_SECTOR_SIZE 2048
DWORD SNA_g_dwNumberOfOccur;
DWORD SNA_g_dwFirstHeaderSize;
DWORD SNA_g_dwHeaderSize;
DWORD SNA_g_dwTotalSector;
DWORD SNA_g_dwConnectedFiles;
/*------------------------------------------------------------------------*/
#pragma warning( disable : 4102 ) // Disable warning messages : unreferenced label
/*
* Function to convert a relocation table file number + file type to a real file handle.
* This is version without protection bigfile.
*/
#include "GAM\structur\engmode.h"
ACP_tdxBool SNA_fn_bGetHandleToRelocationTable( SNA_tdstFile *_p_stFile )
{
char szFileName[256];
char *p_szLevelName, *p_cSubMapDelimiter;
/* ------------------------------------------ */
/* to get begin and end addresses of function */
#ifdef PTC_SYSTEM_ACTIVED
if (PTC_g_bTakeAddresses)
{
PTC_M_AddFunctionCheckSum(0,SNA_fn_bGetHandleToRelocationTable);
return TRUE;
}
#endif
/* ------------------------------------------ */
/* ------------------------------------------ */
PTC_M_DeclareBeginLabel(SNA_fn_bGetHandleToRelocationTable)
/* Loading fix ? */
if( SNA_g_ucNextRelocationTableToLoad[0] == 255 )
{
/* ANNECY OA - 20/07/99 { */
#ifdef RETAIL
sprintf( szFileName, "%c:\\%s\\Fix", g_cCDROM, fn_szGetLevelsDataPath() );
#else
sprintf( szFileName, "%s\\Fix", fn_szGetLevelsDataPath() );
#endif
/* END ANNECY OA } */
}
else
{
#ifdef DEBUG
/* Trying to load a level that does not exist ? */
assert( SNA_g_ucNextRelocationTableToLoad[0] < g_stEngineStructure.ucNumberOfLevels );
#endif
/* ANNECY MT - 30/03/99 { Pc Protection */
/* Trying to load rt? file into BigFile */
if (SNA_fn_bBigFileUsed ())
{
if (SNA_fn_bGetHandleToRelocationTableInBigFile (_p_stFile))
return TRUE;
}
/* END ANNECY MT } */
/* Get level name from its number */
p_szLevelName = g_stEngineStructure.a_szLevelName[SNA_g_ucNextRelocationTableToLoad[0]];
if( (p_cSubMapDelimiter = strchr( p_szLevelName, '$' )) != NULL )
*p_cSubMapDelimiter = 0;
/* Compute full level name (with path) */
/* ANNECY OA - 20/07/99 { */
#ifdef RETAIL
sprintf( szFileName, "%c:\\%s\\%s\\%s", g_cCDROM, fn_szGetLevelsDataPath(), p_szLevelName, p_szLevelName );
#else
sprintf( szFileName, "%s\\%s\\%s", fn_szGetLevelsDataPath(), p_szLevelName, p_szLevelName );
#endif
/* END ANNECY OA } */
if( p_cSubMapDelimiter )
*p_cSubMapDelimiter = '$';
}
/* add file extension (given its type) */
switch( SNA_g_ucNextRelocationTableToLoad[1] )
{
case SNA_C_ucSNARelocationTable: strcat( szFileName, ".rtb" ); break;
case SNA_C_ucGlobalPointersRelocationTable: strcat( szFileName, ".rtp" ); break;
case SNA_C_ucTexturesRelocationTable: strcat( szFileName, ".rtt" ); break;
case SNA_C_ucSoundRelocationTable: strcat( szFileName, ".rts" ); break;
case SNA_C_ucLipsSyncRelocationTable: strcat( szFileName, ".rtl" ); break;
#ifdef DEBUG
/* Unknown relocation file type */
default: assert(0);
#endif
}
PTC_M_DeclareEndLabel(SNA_fn_bGetHandleToRelocationTable)
/* Open it and returns handle. */
/* ANNECY OA - 20/07/99 { */
{
BOOL returnValue = SNA_fn_bFOpen( szFileName, SNA_C_ucRead, 0, _p_stFile );
#ifdef RETAIL
while (returnValue == FALSE)
{
if (MessageBox(NULL, "Inserez le CD dans le lecteur", "CDROM non trouv<75>!", MB_RETRYCANCEL) == IDCANCEL)
{
abort();
}
returnValue = SNA_fn_bFOpen( szFileName, SNA_C_ucRead, 0, _p_stFile );
}
#endif
return returnValue;
/*return SNA_fn_bFOpen( szFileName, SNA_C_ucRead, 0, _p_stFile );*/
}
/* END ANNECY OA } */
}
/* Return the position of a level name in global array of level names. */
unsigned char SNA_fn_ucGetLevelID( char *_p_szLevelName )
{
unsigned int i = g_stEngineStructure.ucNumberOfLevels;
unsigned iLength = strlen( _p_szLevelName );
while( i-- )
{
if( strnicmp( _p_szLevelName, g_stEngineStructure.a_szLevelName[i], iLength ) == 0 )
return i;
}
#ifndef RETAIL
// We did not find the level in list of level => the program will crash. so....
{
FILE *hFile = fopen( "test.log", "at" );
if( hFile )
{
fprintf( hFile, "Can't change to map '%s': not found in map list\n", _p_szLevelName );
fclose( hFile );
exit( 1 );
}
}
assert(0);
#endif
return (unsigned char)-1;
}
/**
* SNA_fn_pLoadRelocationTable :
* Read one .rt? file containing a relocation table.
*/
tdstRelocTable *SNA_fn_pLoadRelocationTable()
{
SNA_tdstFile stFile;
unsigned char ucModule=0xf0,ucBloc=0xf0,ucNbOfBloc,i,ucOldModule=0xf0,ucOldBloc=0xf0;
unsigned long ulSize/*,j*/;
tdstRelocTable *p_stRelocTable;
tdstBloc *p_stBloc;
tdstPtr *p_stPtr;
SNA_fn_vInitArrays();
if( ! SNA_fn_bGetHandleToRelocationTable( &stFile ) )
return 0;
SNA_fn_ulFRead( &ucNbOfBloc , sizeof(char), 1, &stFile );
p_stRelocTable=(tdstRelocTable *)malloc(sizeof(tdstRelocTable));
p_stRelocTable->ucBlocNumber=ucNbOfBloc;
p_stBloc=(tdstBloc *)malloc(sizeof(tdstBloc)*ucNbOfBloc);
p_stRelocTable->p_stBloc=p_stBloc;
for(i=0;i<ucNbOfBloc;i++)
{
ucOldModule=ucModule;
ucOldBloc=ucBloc;
SNA_fn_ulFRead( &ucModule , sizeof(char), 1, &stFile );
SNA_fn_ulFRead( &ucBloc , sizeof(char), 1, &stFile );
if( (ucModule==ucOldModule) && (ucBloc==ucOldBloc) ) // MR0610 (anti-bug)
{
p_stRelocTable->ucBlocNumber--;
break;
}
SNA_fn_ulFRead( &ulSize , sizeof(long), 1, &stFile );
if( ulSize != 0L )
{
p_stPtr=(tdstPtr *)malloc(sizeof(tdstPtr)*ulSize);
/*
for(j=0;j<ulSize;j++)
{
SNA_fn_ulFRead( &p_stPtr[j].p_vPtr , sizeof(long), 1, &stFile );
SNA_fn_ulFRead( &p_stPtr[j].ucTargetModule , sizeof(char), 1, &stFile );
SNA_fn_ulFRead( &p_stPtr[j].ucTargetBlock , sizeof(char), 1, &stFile );
}
*/
SNA_fn_ulFRead( p_stPtr , sizeof(tdstPtr) * ulSize , 1, &stFile );
}
else
{
p_stPtr=0;
}
p_stBloc[i].ucModuleNumber=ucModule;
p_stBloc[i].ucBlocNumber=ucBloc;
p_stBloc[i].ulSize=ulSize;
p_stBloc[i].p_stPtr=p_stPtr;
}
SNA_fn_bFClose( &stFile );
return p_stRelocTable;
}
void SNA_fn_pFreeRelocationTable(tdstRelocTable * p_stRelocTable)
{
unsigned char i;
tdstBloc *p_stBloc;
if(p_stRelocTable!=NULL)
{
p_stBloc=p_stRelocTable->p_stBloc;
for(i=0;i<p_stRelocTable->ucBlocNumber;i++)
{
free(p_stBloc[i].p_stPtr);
}
free(p_stBloc);
free(p_stRelocTable);
}
}
/* ANNECY MT - 30/03/99 { PC Protection */
/*------------------------------------------------------------------------
*
* Author Marc Trabucato
* Date 31 mars 1999
*
* Prototype SNA_fn_vInitBigFile
* Return Type void
*
* Description
*
*------------------------------------------------------------------------*/
void SNA_fn_vInitBigFile()
{
if(SNA_fn_bBigFileUsed ())
{
char szBigFileName[MAX_PATH];
HANDLE hFile;
/* ANNECY OA - 13/07/99 { */
#ifdef RETAIL
sprintf (szBigFileName , "%c:\\%s\\%s", g_cCDROM, fn_szGetLevelsDataPath(), a_BigFilesName[0]);
#else
sprintf (szBigFileName , "%s\\%s", fn_szGetLevelsDataPath(), a_BigFilesName[0]);
#endif
/*sprintf (szBigFileName , "%s\\data.000", fn_szGetLevelsDataPath());*/
/* END ANNECY OA } */
hFile = PTC_CreateFile (szBigFileName , GENERIC_READ , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
/* ANNECY OA - 20/07/99 { */
#ifdef RETAIL
while (hFile == INVALID_HANDLE_VALUE)
{
if (MessageBox(NULL, "Inserez le CD dans le lecteur", "CDROM non trouv<75>!", MB_RETRYCANCEL) == IDCANCEL)
{
abort();
}
hFile = PTC_CreateFile (szBigFileName , GENERIC_READ , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
}
#endif
/* END ANNECY OA } */
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD dwKeys[4];
DWORD dwRead;
DWORD dwValue , dwUnused;
/* read keys */
PTC_ReadFile (hFile , dwKeys , 4 * sizeof(DWORD) , &dwRead , NULL);
/* read Number of map */
PTC_ReadFile (hFile , &dwValue , 4 , &dwRead , NULL);
dwUnused = (dwValue - dwKeys[0]) ^ dwKeys[1];
dwKeys[0] += dwKeys[2];
dwKeys[1] += dwKeys[3];
/* read Number of Occur */
PTC_ReadFile (hFile , &dwValue , 4 , &dwRead , NULL);
SNA_g_dwNumberOfOccur = (dwValue - dwKeys[0]) ^ dwKeys[1];
dwKeys[0] += dwKeys[2];
dwKeys[1] += dwKeys[3];
/* read Header Step */
PTC_ReadFile (hFile , &dwValue , 4 , &dwRead , NULL);
dwUnused = (dwValue - dwKeys[0]) ^ dwKeys[1];
dwKeys[0] += dwKeys[2];
dwKeys[1] += dwKeys[3];
/* read First Header Size */
PTC_ReadFile (hFile , &dwValue , 4 , &dwRead , NULL);
SNA_g_dwFirstHeaderSize = (dwValue - dwKeys[0]) ^ dwKeys[1];
dwKeys[0] += dwKeys[2];
dwKeys[1] += dwKeys[3];
/* read File Step */
PTC_ReadFile (hFile , &dwValue , 4 , &dwRead , NULL);
dwUnused = (dwValue - dwKeys[0]) ^ dwKeys[1];
dwKeys[0] += dwKeys[2];
dwKeys[1] += dwKeys[3];
/* read Sector Size */
PTC_ReadFile (hFile , &dwValue , 4 , &dwRead , NULL);
SNA_g_dwHeaderSize = (dwValue - dwKeys[0]) ^ dwKeys[1];
dwKeys[0] += dwKeys[2];
dwKeys[1] += dwKeys[3];
/* read Number of Sectors */
PTC_ReadFile (hFile , &dwValue , 4 , &dwRead , NULL);
SNA_g_dwTotalSector = (dwValue - dwKeys[0]) ^ dwKeys[1];
dwKeys[0] += dwKeys[2];
dwKeys[1] += dwKeys[3];
/* read Number of Connected Files */
PTC_ReadFile (hFile , &dwValue , 4 , &dwRead , NULL);
SNA_g_dwConnectedFiles = (dwValue - dwKeys[0]) ^ dwKeys[1];
dwKeys[0] += dwKeys[2];
dwKeys[1] += dwKeys[3];
PTC_CloseHandle (hFile);
}
}
}
/*------------------------------------------------------------------------
*
* Author Marc Trabucato
* Date 31 mars 1999
*
* Prototype SNA_fn_bGetHandleToRelocationTableInBigFile
* Parameters _p_stFile :
* Return Type ACP_tdxBool
*
* Description Read rt? files into bigfile for each map
*
*------------------------------------------------------------------------*/
ACP_tdxBool SNA_fn_bGetHandleToRelocationTableInBigFile( SNA_tdstFile *_p_stFile )
{
DWORD dwOffSet;
DWORD dwProtectKey;
HANDLE hFile;
/* ------------------------------------------ */
/* to get begin and end addresses of function */
#ifdef PTC_SYSTEM_ACTIVED
if (PTC_g_bTakeAddresses)
{
PTC_M_AddFunctionCheckSum(1,SNA_fn_bGetHandleToRelocationTableInBigFile);
return TRUE;
}
#endif
/* ------------------------------------------ */
/* ------------------------------------------ */
PTC_M_DeclareBeginLabel(SNA_fn_bGetHandleToRelocationTableInBigFile)
hFile = SNA_fn_hGetOffSetInBigFileWithSinusHeader (&dwOffSet);
if (hFile != INVALID_HANDLE_VALUE)
{
/* seek */
PTC_SetFilePointer (hFile , dwOffSet , NULL , FILE_BEGIN);
/* uses encryption */
SNA_fn_vInitFile (SNA_C_ucUseEncryption , _p_stFile);
// compute crypt key */*
SNA_g_ucNextRelocationTableToLoad[3] = ~SNA_g_ucNextRelocationTableToLoad[2];
_p_stFile -> ulCryptKey = SNA_fn_dwGetCryptKeyRelocationTable();
SNA_g_a_dwInitKeyRelocationTableLoaded [SNA_g_dwNumberOfRelocationTableLoaded] = *((DWORD*)SNA_g_ucNextRelocationTableToLoad);
_p_stFile -> hFile = hFile;
_p_stFile -> bReadSuccess = TRUE;
/* read protect-key */
SNA_fn_ulFRead (&dwProtectKey , 4 , 1 , _p_stFile);
SNA_g_a_dwProtectKeyRelocationTableLoaded [SNA_g_dwNumberOfRelocationTableLoaded++] = dwProtectKey;
SNA_M_vUpdateOccurrenceToLoad();
return TRUE;
}
PTC_M_DeclareEndLabel(SNA_fn_bGetHandleToRelocationTableInBigFile)
return FALSE;
}
/*------------------------------------------------------------------------
*
* Author Marc Trabucato
* Date 31 mars 1999
*
* Prototype SNA_fn_dwGetOffSetInBigFileWithSinusHeader
* Return Type DWORD
*
* Description each occurence has it's own header in the file
* Headers are placed int the file using a recurent serie
*------------------------------------------------------------------------*/
HANDLE SNA_fn_hGetOffSetInBigFileWithSinusHeader(DWORD *p_dwOffSet)
{
char szBigFileName[MAX_PATH];
HANDLE hFile;
/* ANNECY OA - 13/07/99 { */
#ifdef RETAIL
sprintf (szBigFileName , "%c:\\%s\\%s", g_cCDROM, fn_szGetLevelsDataPath(), a_BigFilesName[0]);
#else
sprintf (szBigFileName , "%s\\%s", fn_szGetLevelsDataPath(), a_BigFilesName[0]);
#endif
/*sprintf (szBigFileName , "%s\\data.000", fn_szGetLevelsDataPath());*/
/* END ANNECY OA } */
hFile = PTC_CreateFile (szBigFileName , GENERIC_READ , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
/* ANNECY OA - 20/07/99 { */
#ifdef RETAIL
while (hFile == INVALID_HANDLE_VALUE)
{
if (MessageBox(NULL, "Inserez le CD dans le lecteur", "CDROM non trouv<75>!", MB_RETRYCANCEL) == IDCANCEL)
{
abort();
}
hFile = PTC_CreateFile (szBigFileName , GENERIC_READ , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
}
#endif
/* END ANNECY OA } */
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD dwFile , dwOccur , dwOffSetHeader;
DWORD dwKeys[4];
DWORD dwRead;
DWORD dwValue;
DWORD dwCount;
DWORD dwN;
double fN , fValue , fA , fB , fC, fInteger;
// Compute Occur and File
dwFile = SNA_g_ucNextRelocationTableToLoad[0] * 4;
switch( SNA_g_ucNextRelocationTableToLoad[1] )
{
case SNA_C_ucSNARelocationTable: break;
case SNA_C_ucGlobalPointersRelocationTable: dwFile += 1; break;
case SNA_C_ucSoundRelocationTable: dwFile += 2; break;
case SNA_C_ucTexturesRelocationTable: dwFile += 3; break;
#ifdef DEBUG
case SNA_C_ucLipsSyncRelocationTable:
default: assert(0);
#endif
}
dwOccur = (SNA_g_ucNextRelocationTableToLoad[2]) % SNA_g_dwNumberOfOccur;
SNA_g_ucNextRelocationTableToLoad[2] = (unsigned char) (dwOccur & 0x000000FF);
// seek wanted header
fA = 0.69314;
fB = 1.69314;
fC = 0.52658;
fN = 1.06913;
for (dwN = 0 ; dwN < dwOccur ; dwN++)
{
fN = fN + fA * fabs(sin(fB * dwN * dwN)) + fC;
//fN = floor(fN * 1000000.0) / 1000000.0;
}
fValue = floor(modf(fN , &fInteger) * 1000000.0) / 1000000.0;
dwOffSetHeader = SNA_g_dwHeaderSize * (DWORD)floor(fValue * SNA_g_dwTotalSector) + SNA_g_dwFirstHeaderSize;
PTC_SetFilePointer (hFile , dwOffSetHeader , NULL , FILE_BEGIN);
// read crypt key
PTC_ReadFile (hFile , dwKeys , 4 * sizeof(DWORD) , &dwRead , NULL);
// seek wanted file
for (dwCount = 0 ; dwCount < dwFile ; dwCount++)
{
dwKeys[0] += dwKeys[2];
dwKeys[1] += dwKeys[3];
}
PTC_SetFilePointer (hFile , dwFile * 4 , NULL , FILE_CURRENT);
/* read OffSet */
PTC_ReadFile (hFile , &dwValue , 4 , &dwRead , NULL);
*p_dwOffSet = (dwValue - dwKeys[0]) ^ dwKeys[1];
/* ANNECY OA - 15/07/99 { */
/* Multi files managment */
{
char sBuffer[512];
char nbuffer[512];
long lSectorOffset = SNA_g_dwTotalSector / SNA_g_dwConnectedFiles;
long lByteOffset = lSectorOffset*M_SECTOR_SIZE;
long lHigherFileNumber = *p_dwOffSet / lByteOffset;
long lFileToOpen = PTC_fn_lGetRandomRange(0, lHigherFileNumber);
PTC_SetFilePointer (hFile , *p_dwOffSet , NULL , FILE_BEGIN);
PTC_ReadFile (hFile , sBuffer , 512 * sizeof(char) , &dwRead , NULL);
*p_dwOffSet -= lFileToOpen*lByteOffset;
PTC_CloseHandle(hFile);
/* ANNECY OA - 20/07/99 { */
#ifdef RETAIL
sprintf (szBigFileName , "%c:\\%s\\%s", g_cCDROM, fn_szGetLevelsDataPath(), a_BigFilesName[lFileToOpen]);
#else
sprintf (szBigFileName , "%s\\%s", fn_szGetLevelsDataPath(), a_BigFilesName[lFileToOpen]);
#endif
/* END ANNECY OA } */
hFile = PTC_CreateFile (szBigFileName , GENERIC_READ , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
/* ANNECY OA - 20/07/99 { */
#ifdef RETAIL
while (hFile == INVALID_HANDLE_VALUE)
{
if (MessageBox(NULL, "Inserez le CD dans le lecteur", "CDROM non trouv<75>!", MB_RETRYCANCEL) == IDCANCEL)
{
abort();
}
hFile = PTC_CreateFile (szBigFileName , GENERIC_READ , 0 , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL);
}
#endif
/* END ANNECY OA } */
PTC_SetFilePointer (hFile , *p_dwOffSet , NULL , FILE_BEGIN);
PTC_ReadFile (hFile , nbuffer , 512 * sizeof(char) , &dwRead , NULL);
}
/* END ANNECY OA } */
}
return hFile;
}
/* END ANNECY MT } */
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/
/*------------------------------------------------------------------------*/

View File

@@ -0,0 +1,143 @@
/*=========================================================================
* Snasnd.c : Save & Read the sound pointers
*
* Version 1.0
* Creation date 03/09/97
* Revision date
*
* (c) Ubi R&D 1997
*=======================================================================*/
#include "ACP_Base.h"
#include "ToolsCPA.h"
#include "SCR.h"
#include "SND.h"
#include "SNA.h"
#include "acp_opfi.h"
FILE *g_xSoundFile; // Sound pointers file
/*-----------------------------------------------------------------------------
* Description : Open sound pointers file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_xWriteOpenSoundTableFile(char *szFileName)
{
SNA_fn_vInitArrays();
g_xSoundFile=fopen(szFileName,"wb");
}
void SNA_fn_xReadOpenSoundTableFile(char *szFileName)
{
SNA_fn_vInitArrays();
//g_xSoundFile=fopen(szFileName,"rb"); Multi-install
ACP_M_OPENFILE(fopen,g_xSoundFile,NULL,szFileName,(szFileName,"rb"));
SNA_M_LoadUsedRelocationTable();
}
/*-----------------------------------------------------------------------------
* Description : Close sound pointers file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vCloseSoundTableFile()
{
SNA_M_FreeRelocationTable();
fclose(g_xSoundFile);
}
/*-----------------------------------------------------------------------------
* Description : Write a Id/pointer sound couple in file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vWriteSoundEntryInSoundTableFile(unsigned long ulId,unsigned long ulPointerAdr)
{
if (SNA_fn_ucGetLoadType()==SNA_SAVE_SNAPSHOT)
{
fwrite(&ulId,4,1,g_xSoundFile);
fwrite(&ulPointerAdr,4,1,g_xSoundFile);
}
}
/*-----------------------------------------------------------------------------
* Description : Read and update all sound pointers
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 03/09/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vReadAndUpdateSoundPointers(char *szFileName)
{
unsigned long ulId,ulOldAdrPointer,ulNewPointer;
unsigned long *p_ulSound;
/* unsigned long j; */
struct tdstPtr_ *p_stCurrentPtr = &SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[0];
while (!feof(g_xSoundFile))
{
if(!fread(&ulId,4,1,g_xSoundFile))
{
#ifdef DEBUG
OutputDebugString("\n End of SoundFile !!!");
#endif
break;
}
if(!fread(&ulOldAdrPointer,4,1,g_xSoundFile))
{
#ifdef DEBUG
OutputDebugString("\n End of SoundFile !!!");
#endif
break;
}
ulNewPointer=(unsigned long)SND_fn_pGetBinEvent(ulId);
/*
for (j=0;j<SNA_g_PTCRelocationTable->p_stBloc[0].ulSize;j++)
{
unsigned char ucModuleNumber,ucBlocNumber;
ucModuleNumber=SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[j].ucTargetModule;
ucBlocNumber=SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[j].ucTargetBlock;
if (((unsigned long)p_ulSound==SNA_g_PTCRelocationTable->p_stBloc[0].p_stPtr[j].p_vPtr)&&(g_a_bIsBlocRelocated[ucModuleNumber][ucBlocNumber]))
{
((unsigned long)p_ulSound)+=g_a_ulOffset[ucModuleNumber][ucBlocNumber];
}
}
*/
assert( p_stCurrentPtr->p_vPtr == ulOldAdrPointer );
ulOldAdrPointer += g_a_ulOffset[p_stCurrentPtr->ucTargetModule][p_stCurrentPtr->ucTargetBlock];
p_stCurrentPtr ++;
p_ulSound=(unsigned long *)ulOldAdrPointer;
*p_ulSound=ulNewPointer;
}
fclose(g_xSoundFile);
}

View File

@@ -0,0 +1,406 @@
/*=========================================================================
* Snasyn.c : Save & Read the lips synchro pointers
*
* Version 1.0
* Creation date 03/09/97
* Revision date
*
* (c) Ubi R&D 1997
*=======================================================================*/
#ifdef D_USE_LIPSYNC
#include "ACP_Base.h"
#include "ToolsCPA.h"
#include "GAM\LipsSync.h"
#include "GAM\LoadLSyn.h"
#include "GAM\LSMem.h"
#include "SCR.h"
#include "SNA.h"
#include "SNA\snasyn.h"
#include "acp_opfi.h"
#include "AI\AIBase\StrIntel.h"
FILE *g_xLipsSynchFile; // LipsSynch pointers file
struct tdstRelocTable_ *g_p_stGPointerRelocTableLS;
FILE *g_p_xLipsSynchroBlocFile;
tdstLipsSynchroBinTable *g_a_p_stLSBinTable;
long g_lNumberOfLSTable;
#ifndef U64
extern int g_iComplete;
#endif
/*-----------------------------------------------------------------------------
* Description : Open LipsSynch pointers file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 09/12/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_xWriteOpenLipsSynchTableFile(char *szFileName)
{
SNA_fn_vInitArrays();
g_xLipsSynchFile=fopen(szFileName,"wb");
}
unsigned long fn_ulGetFileSize(char *szFilename)
{ unsigned long ulFileSize;
LPWIN32_FIND_DATA lpFFD=(LPWIN32_FIND_DATA)malloc(sizeof(WIN32_FIND_DATA));
if (FindFirstFile(szFilename,lpFFD) == INVALID_HANDLE_VALUE)
{
free(lpFFD);
return 0;
}
ulFileSize=lpFFD->nFileSizeHigh * MAXDWORD + lpFFD->nFileSizeLow;
free(lpFFD);
return ulFileSize;
}
ACP_tdxBool SNA_fn_xReadOpenLipsSynchTableFile(char *szFileName)
{
unsigned long ulFileSize;
SNA_fn_vInitArrays();
if (!g_iComplete)
{
ACP_M_OPENLANGFILE(fn_ulGetFileSize,ulFileSize,0,szFileName,(szFileName));
if (!ulFileSize)
return FALSE;
}
else
{
if (!fn_ulGetFileSize(szFileName))
return FALSE;
}
//g_xLipsSynchFile=fopen(szFileName,"rb"); Multi-install and multi-language
ACP_M_OPENLANGFILE(fopen,g_xLipsSynchFile,NULL,szFileName,(szFileName,"rb"));
/*
szFileName[strlen(szFileName)-3]=0;
strcat(szFileName,"rtl");
g_p_stGPointerRelocTableLS=SNA_fn_pLoadRelocationTable(szFileName); // Modifier le filename...
*/
g_p_stGPointerRelocTableLS=SNA_fn_pLoadRelocationTable();
return TRUE;
}
/*-----------------------------------------------------------------------------
* Description : Close LipsSynch pointers file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 09/12/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vCloseLipsSynchTableFile()
{
SNA_fn_pFreeRelocationTable(g_p_stGPointerRelocTableLS);
fclose(g_xLipsSynchFile);
}
/*-----------------------------------------------------------------------------
* Description : Write a LS filename/IA node pointer couple in file
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 09/12/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vWriteLipsSynchEntryInLipsSynchTableFile(char *szLSFilename,unsigned long ulNodeAdr)
{ char szLSFilename255[255];
strcpy(szLSFilename255,szLSFilename);
if (SNA_fn_ucGetLoadType()==SNA_SAVE_SNAPSHOT)
{
fwrite(szLSFilename255,255,1,g_xLipsSynchFile);
fwrite(&ulNodeAdr,4,1,g_xLipsSynchFile);
}
}
// MR0912
void fn_vInitNodeLipSynchroRefWithSNA(tdstNodeInterpret *p_stNode,char *szLipsFileName)
{
tdstLipsSynchroTable *p_stLSTable;
p_stLSTable=fn_p_stReturnLipsSynchTable(szLipsFileName);
M_hLipSynchroHandleIdInterpret(p_stNode) = p_stLSTable;
}
void fn_vUpdateSoundPointersForLipsSynch()
{ ACP_tdxIndex xJ;
for (xJ=0;xJ<g_lNumberOfLSTable;xJ++)
{
g_a_p_stLSBinTable[xJ].p_stLSTable->p_stSndEvent=SND_fn_pGetBinEvent((unsigned long)g_a_p_stLSBinTable[xJ].p_stLSTable->p_stSndEvent);
}
}
/*-----------------------------------------------------------------------------
* Description : Read and update all LipsSynch pointers
*-----------------------------------------------------------------------------
* Input : Name of the file
* Output : None
*-----------------------------------------------------------------------------
* Creation date : 09/12/97 Author : Micha<68>l
*-----------------------------------------------------------------------------
* Modification date : Modification Author :
* Modifications :
*---------------------------------------------------------------------------*/
void SNA_fn_vReadAndUpdateLipsSynchPointers()
{
char szLSFileName[255];
unsigned long ulOldAdrPointer;
unsigned long *p_ulLipsSynch;
unsigned long j;
while (!feof(g_xLipsSynchFile))
{
if(!fread(szLSFileName,255,1,g_xLipsSynchFile))
{
OutputDebugString("\n End of LipsSynchFile !!!");
break;
}
if(!fread(&ulOldAdrPointer,4,1,g_xLipsSynchFile))
{
OutputDebugString("\n End of LipsSynchFile !!!");
break;
}
p_ulLipsSynch=(unsigned long *)ulOldAdrPointer;
for (j=0;j<g_p_stGPointerRelocTableLS->p_stBloc[0].ulSize;j++)
{
unsigned char ucModuleNumber,ucBlocNumber;
ucModuleNumber=g_p_stGPointerRelocTableLS->p_stBloc[0].p_stPtr[j].ucModuleNumber;
ucBlocNumber=g_p_stGPointerRelocTableLS->p_stBloc[0].p_stPtr[j].ucBlocNumber;
if (((unsigned long)p_ulLipsSynch==g_p_stGPointerRelocTableLS->p_stBloc[0].p_stPtr[j].p_vPtr)&&(g_a_bIsBlocRelocated[ucModuleNumber][ucBlocNumber]))
{
((unsigned long)p_ulLipsSynch)+=g_a_ulOffset[ucModuleNumber][ucBlocNumber];
}
}
fn_vInitNodeLipSynchroRefWithSNA((tdstNodeInterpret *)p_ulLipsSynch,szLSFileName);
}
fclose(g_xLipsSynchFile);
fn_vUpdateSoundPointersForLipsSynch();
}
/**************************************************************************************/
// SNASHOTISATION (MR0912)
/**************************************************************************************/
void fn_vOpenWriteLipsSynchroBloc(char *szFileName)
{
g_p_xLipsSynchroBlocFile=fopen(szFileName,"wb");
g_lNumberOfLSTable=0;
}
void fn_vCloseWriteLipsSynchroBloc()
{
fwrite(&g_lNumberOfLSTable,4,1,g_p_xLipsSynchroBlocFile);
fclose(g_p_xLipsSynchroBlocFile);
}
void fn_vWriteLipsSynchroBloc(tdstLipsSynchroTable *p_stLSTable, char *szSectionName)
{
tdstLipsSynchroTable* hLST=p_stLSTable;
ACP_tdxIndex xI;
unsigned long BinId;
g_lNumberOfLSTable++;
// Write section name
fwrite(szSectionName,1,255,g_p_xLipsSynchroBlocFile);
fwrite(&hLST->lNumberOfFrames,4,1,g_p_xLipsSynchroBlocFile);
fwrite(&hLST->lSpeed,4,1,g_p_xLipsSynchroBlocFile);
BinId=SND_fn_ulGetEventBinIdFromPointer(hLST->p_stSndEvent);
fwrite(&BinId,4,1,g_p_xLipsSynchroBlocFile);
for(xI=0;xI<MAX_NUM_CHAN_SYN;++xI)
fwrite(&(hLST->ucChannelAffected[xI]),1,1,g_p_xLipsSynchroBlocFile);
fwrite(&hLST->ucNumberOfChannelAffected,1,1,g_p_xLipsSynchroBlocFile);
fwrite(&hLST->iIndex,4,1,g_p_xLipsSynchroBlocFile);
fwrite(&hLST->lNumberOfTexts,4,1,g_p_xLipsSynchroBlocFile);
if(hLST->p_stDialTexts==NULL)
{
BinId=0L;
fwrite(&BinId,4,1,g_p_xLipsSynchroBlocFile);
}
else
{
BinId=1L;
fwrite(&BinId,4,1,g_p_xLipsSynchroBlocFile);
}
fwrite(&hLST->lNumberOfActings,4,1,g_p_xLipsSynchroBlocFile);
if(hLST->p_stActing==NULL)
{
BinId=0L;
fwrite(&BinId,4,1,g_p_xLipsSynchroBlocFile);
}
else
{
BinId=1L;
fwrite(&BinId,4,1,g_p_xLipsSynchroBlocFile);
}
// Now the table of synchro events
for(xI=0;xI<hLST->lNumberOfFrames;++xI)
{
fwrite(&(hLST->p_stTable[xI].ucPhoneme),4,1,g_p_xLipsSynchroBlocFile);
fwrite(&(hLST->p_stTable[xI].ucIntensity),4,1,g_p_xLipsSynchroBlocFile);
fwrite(&(hLST->p_stTable[xI].ucExpression),4,1,g_p_xLipsSynchroBlocFile);
}
// Then the dial texts
if(hLST->p_stDialTexts!=NULL)
{
for(xI=0;xI<hLST->lNumberOfTexts;++xI)
{
fwrite(&(hLST->p_stDialTexts[xI].lFrameNumber),4,1,g_p_xLipsSynchroBlocFile);
fwrite(&(hLST->p_stDialTexts[xI].xPosX),4,1,g_p_xLipsSynchroBlocFile);
fwrite(&(hLST->p_stDialTexts[xI].xPosY),4,1,g_p_xLipsSynchroBlocFile);
}
}
// Finally the acting pointer
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!!! NE MARCHERA PAS !!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(hLST->p_stActing!=NULL)
{
for(xI=0;xI<hLST->lNumberOfActings;++xI)
{
fwrite(&(hLST->p_stActing[xI].lFrameNumber),4,1,g_p_xLipsSynchroBlocFile);
fwrite(&(hLST->p_stActing[xI].hNewState),4,1,g_p_xLipsSynchroBlocFile);
}
}
}
void fn_vReadAllLipsSynchroBlocs(char *szFileName)
{
tdstLipsSynchroTable* hLST;
ACP_tdxIndex xI,xJ;
unsigned long BinId;
LSY_fn_vFreeLipsSynchroBlock();
ACP_M_OPENLANGFILE(fopen,g_p_xLipsSynchroBlocFile,NULL,szFileName,(szFileName,"rb"));
fseek(g_p_xLipsSynchroBlocFile,-4,SEEK_END);
fread(&g_lNumberOfLSTable,4,1,g_p_xLipsSynchroBlocFile);
fseek(g_p_xLipsSynchroBlocFile,0,SEEK_SET);
g_a_p_stLSBinTable=fn_xAllocateLipsSynchroBinTable(g_lNumberOfLSTable);
//while (!feof(g_p_xLipsSynchroBlocFile))
for (xJ=0;xJ<g_lNumberOfLSTable;xJ++)
{
fread(g_a_p_stLSBinTable[xJ].szSectionName,1,255,g_p_xLipsSynchroBlocFile);
hLST=fn_xAllocateLipsSynchroTable();
g_a_p_stLSBinTable[xJ].p_stLSTable=hLST;
fread(&hLST->lNumberOfFrames,4,1,g_p_xLipsSynchroBlocFile);
fread(&hLST->lSpeed,4,1,g_p_xLipsSynchroBlocFile);
// A voir...
fread(&hLST->p_stSndEvent,4,1,g_p_xLipsSynchroBlocFile);
for(xI=0;xI<MAX_NUM_CHAN_SYN;++xI)
fread(&(hLST->ucChannelAffected[xI]),1,1,g_p_xLipsSynchroBlocFile);
fread(&hLST->ucNumberOfChannelAffected,1,1,g_p_xLipsSynchroBlocFile);
fread(&hLST->iIndex,4,1,g_p_xLipsSynchroBlocFile);
fread(&hLST->lNumberOfTexts,4,1,g_p_xLipsSynchroBlocFile);
fread(&BinId,4,1,g_p_xLipsSynchroBlocFile);
if (!BinId)
hLST->p_stDialTexts=NULL;
else
hLST->p_stDialTexts=fn_xAllocateDialTexts(hLST->lNumberOfTexts);
fread(&hLST->lNumberOfActings,4,1,g_p_xLipsSynchroBlocFile);
fread(&BinId,4,1,g_p_xLipsSynchroBlocFile);
if (!BinId)
hLST->p_stActing=NULL;
else
hLST->p_stActing=fn_xAllocateActing(hLST->lNumberOfActings);
// Now the table of synchro events
hLST->p_stTable=fn_xAllocateLipsSynchroEvents(hLST->lNumberOfFrames);
for(xI=0;xI<hLST->lNumberOfFrames;++xI)
{
fread(&(hLST->p_stTable[xI].ucPhoneme),4,1,g_p_xLipsSynchroBlocFile);
fread(&(hLST->p_stTable[xI].ucIntensity),4,1,g_p_xLipsSynchroBlocFile);
fread(&(hLST->p_stTable[xI].ucExpression),4,1,g_p_xLipsSynchroBlocFile);
}
// Then the dial texts
if(hLST->p_stDialTexts!=NULL)
{
for(xI=0;xI<hLST->lNumberOfTexts;++xI)
{
fread(&(hLST->p_stDialTexts[xI].lFrameNumber),4,1,g_p_xLipsSynchroBlocFile);
fread(&(hLST->p_stDialTexts[xI].xPosX),4,1,g_p_xLipsSynchroBlocFile);
fread(&(hLST->p_stDialTexts[xI].xPosY),4,1,g_p_xLipsSynchroBlocFile);
}
}
// Finally the acting pointer
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!!! NE MARCHERA PAS !!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if(hLST->p_stActing!=NULL)
{
for(xI=0;xI<hLST->lNumberOfActings;++xI)
{
fread(&(hLST->p_stActing[xI].lFrameNumber),4,1,g_p_xLipsSynchroBlocFile);
fread(&(hLST->p_stActing[xI].hNewState),4,1,g_p_xLipsSynchroBlocFile);
}
}
//xJ++;
}
fclose(g_p_xLipsSynchroBlocFile);
}
tdstLipsSynchroTable *fn_p_stReturnLipsSynchTable(char *szSectionName)
{ ACP_tdxIndex xJ;
for (xJ=0;xJ<g_lNumberOfLSTable;xJ++)
if (!strcmp(szSectionName,g_a_p_stLSBinTable[xJ].szSectionName))
return g_a_p_stLSBinTable[xJ].p_stLSTable;
return NULL;
}
#endif // D_USE_LIPSYNC

View File

@@ -0,0 +1,23 @@
/*=========================================================================
* Snasnd.c : Save & Read the sound pointers
*
* Version 1.0
* Creation date 03/09/97
* Revision date
*
* (c) Ubi R&D 1997
*=======================================================================*/
#include "ToolsCPA.h"
#include "SNA.h"
unsigned long SNA_fn_ulGetMaxVignetteValueForLevel()
{
return( 2*SNA_g_ulNbBlocksInLevel+1 // 2 for each level block+1 for the reloc table
+ 2 // 2 for global pointers (1 for reloc table+1 for all pointers)
+ 1 // 1 for textures.
+ 1 // 1 for fn_vInitAllObjectsWhenMapJustLoaded()
);
}