summaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
authorNikolay Korolev <nickvnuk@gmail.com>2020-04-06 18:26:04 +0200
committerGitHub <noreply@github.com>2020-04-06 18:26:04 +0200
commitb991fd9766c77354454c76c906f7806680605500 (patch)
treef7425645eb83088646a72b713cd08a665947650e /src/render
parentImplement Init for Stats (diff)
parentfixed look behind bug (diff)
downloadre3-b991fd9766c77354454c76c906f7806680605500.tar
re3-b991fd9766c77354454c76c906f7806680605500.tar.gz
re3-b991fd9766c77354454c76c906f7806680605500.tar.bz2
re3-b991fd9766c77354454c76c906f7806680605500.tar.lz
re3-b991fd9766c77354454c76c906f7806680605500.tar.xz
re3-b991fd9766c77354454c76c906f7806680605500.tar.zst
re3-b991fd9766c77354454c76c906f7806680605500.zip
Diffstat (limited to 'src/render')
-rw-r--r--src/render/Coronas.cpp3
-rw-r--r--src/render/Font.cpp1151
-rw-r--r--src/render/Font.h38
-rw-r--r--src/render/Glass.cpp720
-rw-r--r--src/render/Glass.h51
-rw-r--r--src/render/Hud.cpp88
-rw-r--r--src/render/Renderer.cpp6
-rw-r--r--src/render/Rubbish.cpp1
-rw-r--r--src/render/Rubbish.h1
-rw-r--r--src/render/Shadows.h1
-rw-r--r--src/render/Skidmarks.cpp1
-rw-r--r--src/render/Skidmarks.h1
-rw-r--r--src/render/SpecialFX.cpp1
-rw-r--r--src/render/SpecialFX.h1
-rw-r--r--src/render/WaterCannon.cpp320
-rw-r--r--src/render/WaterCannon.h37
-rw-r--r--src/render/WeaponEffects.cpp113
-rw-r--r--src/render/WeaponEffects.h30
18 files changed, 1899 insertions, 665 deletions
diff --git a/src/render/Coronas.cpp b/src/render/Coronas.cpp
index b0868d0a..c934540b 100644
--- a/src/render/Coronas.cpp
+++ b/src/render/Coronas.cpp
@@ -59,9 +59,6 @@ int &CCoronas::bChangeBrightnessImmediately = *(int*)0x8E2C30;
CRegisteredCorona *CCoronas::aCoronas = (CRegisteredCorona*)0x72E518;
-//WRAPPER void CCoronas::Render(void) { EAXJMP(0x4F8FB0); }
-//WRAPPER void CCoronas::RenderReflections(void) { EAXJMP(0x4F9B40); }
-
const char aCoronaSpriteNames[][32] = {
"coronastar",
"corona",
diff --git a/src/render/Font.cpp b/src/render/Font.cpp
index 7a16ad03..6f336f1e 100644
--- a/src/render/Font.cpp
+++ b/src/render/Font.cpp
@@ -1,515 +1,636 @@
-#include "common.h"
-#include "patcher.h"
-#include "Sprite2d.h"
-#include "TxdStore.h"
-#include "Font.h"
-
-CFontDetails &CFont::Details = *(CFontDetails*)0x8F317C;
-int16 &CFont::NewLine = *(int16*)0x95CC94;
-CSprite2d *CFont::Sprite = (CSprite2d*)0x95CC04;
-
-int16 CFont::Size[3][193] = {
- {
- 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17, 13, 31,
- 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10, 35, 26, 26, 26, 26,
- 30, 26, 24, 23, 24, 22, 21, 24, 26, 10, 20, 26, 22, 29, 26, 25,
- 23, 25, 24, 24, 22, 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37,
- 35, 21, 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21, 21,
- 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 33, 33, 33, 33, 35,
- 27, 27, 27, 27, 32, 24, 23, 23, 23, 23, 11, 11, 11, 11, 26, 26,
- 26, 26, 26, 26, 26, 25, 26, 21, 21, 21, 21, 32, 23, 22, 22, 22,
- 22, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 26, 21, 24,
- 12, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
- 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 18, 26, 26,
- 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
- 20
- },
-
- {
- 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11, 17, 13, 33,
- 28, 14, 22, 21, 24, 23, 23, 21, 23, 22, 10, 35, 13, 35, 13, 33,
- 5, 25, 22, 23, 24, 21, 21, 24, 24, 9, 20, 24, 21, 27, 25, 25,
- 22, 25, 23, 20, 23, 23, 23, 31, 23, 23, 23, 37, 33, 37, 35, 37,
- 35, 21, 19, 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21,
- 20, 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33, 33, 35,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 16
- },
-
- {
- 15, 14, 16, 25, 19, 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27,
- 19, 18, 19, 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35,
- 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29, 19, 20,
- 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, 33, 31, 39, 37, 39,
- 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23, 23,
- 20, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35, 35, 35, 35, 37,
- 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, 9, 9, 9, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 30, 19, 19, 19, 19,
- 19, 10, 10, 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35,
- 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 19, 19,
- 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
- 19
- }
-};
-
-uint16 foreign_table[128] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 176, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 177, 0, 0, 0, 0, 0, 95, 0, 0, 0, 0, 175,
- 128, 129, 130, 0, 131, 0, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
- 0, 173, 142, 143, 144, 0, 145, 0, 0, 146, 147, 148, 149, 0, 0, 150,
- 151, 152, 153, 0, 154, 0, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
- 0, 174, 165, 166, 167, 0, 168, 0, 0, 169, 170, 171, 172, 0, 0, 0,
-};
-
-void
-CFont::Initialise(void)
-{
- int slot;
-
- slot = CTxdStore::AddTxdSlot("fonts");
- CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD");
- CTxdStore::AddRef(slot);
- CTxdStore::PushCurrentTxd();
- CTxdStore::SetCurrentTxd(slot);
- Sprite[0].SetTexture("font2", "font2_mask");
- Sprite[1].SetTexture("pager", "pager_mask");
- Sprite[2].SetTexture("font1", "font1_mask");
- SetScale(1.0f, 1.0f);
- SetSlantRefPoint(SCREEN_WIDTH, 0.0f);
- SetSlant(0.0f);
- SetColor(CRGBA(0xFF, 0xFF, 0xFF, 0));
- SetJustifyOff();
- SetCentreOff();
- SetWrapx(640.0f);
- SetCentreSize(640.0f);
- SetBackgroundOff();
- SetBackgroundColor(CRGBA(0x80, 0x80, 0x80, 0x80));
- SetBackGroundOnlyTextOff();
- SetPropOn();
- SetFontStyle(0);
- SetRightJustifyWrap(0.0f);
- SetAlphaFade(255.0f);
- SetDropShadowPosition(0);
- CTxdStore::PopCurrentTxd();
-}
-
-void
-CFont::Shutdown(void)
-{
- Sprite[0].Delete();
- Sprite[1].Delete();
- Sprite[2].Delete();
- CTxdStore::RemoveTxdSlot(CTxdStore::FindTxdSlot("fonts"));
-}
-
-void
-CFont::InitPerFrame(void)
-{
- Details.bank = CSprite2d::GetBank(30, Sprite[0].m_pTexture);
- CSprite2d::GetBank(15, Sprite[1].m_pTexture);
- CSprite2d::GetBank(15, Sprite[2].m_pTexture);
- SetDropShadowPosition(0);
- NewLine = 0;
-}
-
-void
-CFont::PrintChar(float x, float y, uint16 c)
-{
- if(x <= 0.0f || x > SCREEN_WIDTH ||
- y <= 0.0f || y > SCREEN_HEIGHT) // BUG: game uses SCREENW again
- return;
-
- float w = GetCharacterWidth(c) / 32.0f;
- float xoff = c & 0xF;
- float yoff = c >> 4;
-
- if(Details.style == FONT_BANK || Details.style == FONT_HEADING){
- if(Details.dropShadowPosition != 0){
- CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank
- CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition),
- y + SCREEN_SCALE_Y(Details.dropShadowPosition),
- x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f,
- y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY * 0.5f),
- Details.dropColor,
- xoff/16.0f, yoff/12.8f,
- (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f,
- xoff/16.0f, (yoff+1.0f)/12.8f,
- (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.0001f);
- }
- CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank
- CRect(x, y,
- x + 32.0f * Details.scaleX * 1.0f,
- y + 40.0f * Details.scaleY * 0.5f),
- Details.color,
- xoff/16.0f, yoff/12.8f,
- (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f,
- xoff/16.0f, (yoff+1.0f)/12.8f - 0.002f,
- (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.002f);
- }else{
- CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank
- CRect(x, y,
- x + 32.0f * Details.scaleX * w,
- y + 32.0f * Details.scaleY * 0.5f),
- Details.color,
- xoff/16.0f, yoff/16.0f,
- (xoff+w)/16.0f, yoff/16.0f,
- xoff/16.0f, (yoff+1.0f)/16.0f,
- (xoff+w)/16.0f - 0.0001f, (yoff+1.0f)/16.0f - 0.0001f);
- }
-}
-
-void
-CFont::PrintString(float xstart, float ystart, uint16 *s)
-{
- CRect rect;
- int numSpaces;
- float lineLength;
- float x, y;
- bool first;
- uint16 *start, *t;
-
- if(*s == '*')
- return;
-
- if(Details.background){
- GetNumberLines(xstart, ystart, s); // BUG: result not used
- GetTextRect(&rect, xstart, ystart, s);
- CSprite2d::DrawRect(rect, Details.backgroundColor);
- }
-
- lineLength = 0.0f;
- numSpaces = 0;
- first = true;
- if(Details.centre || Details.rightJustify)
- x = 0.0f;
- else
- x = xstart;
- y = ystart;
- start = s;
-
- // This is super ugly, I blame R*
- for(;;){
- for(;;){
- for(;;){
- if(*s == '\0')
- return;
- int xend = Details.centre ? Details.centreSize :
- Details.rightJustify ? xstart - Details.rightJustifyWrap :
- Details.wrapX;
- if(x + GetStringWidth(s) > xend && !first){
- // flush line
- float spaceWidth = !Details.justify || Details.centre ? 0.0f :
- (Details.wrapX - lineLength) / numSpaces;
- float xleft = Details.centre ? xstart - x/2 :
- Details.rightJustify ? xstart - x :
- xstart;
- PrintString(xleft, y, start, s, spaceWidth);
- // reset things
- lineLength = 0.0f;
- numSpaces = 0;
- first = true;
- if(Details.centre || Details.rightJustify)
- x = 0.0f;
- else
- x = xstart;
- y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY;
- start = s;
- }else
- break;
- }
- // advance by one word
- t = GetNextSpace(s);
- if(t[0] == '\0' ||
- t[0] == ' ' && t[1] == '\0')
- break;
- if(!first)
- numSpaces++;
- first = false;
- x += GetStringWidth(s) + GetCharacterSize(*t - ' ');
- lineLength = x;
- s = t+1;
- }
- // print rest
- if(t[0] == ' ' && t[1] == '\0')
- t[0] = '\0';
- x += GetStringWidth(s);
- s = t;
- float xleft = Details.centre ? xstart - x/2 :
- Details.rightJustify ? xstart - x :
- xstart;
- PrintString(xleft, y, start, s, 0.0f);
- }
-}
-
-int
-CFont::GetNumberLines(float xstart, float ystart, uint16 *s)
-{
- int n;
- float x, y;
- uint16 *t;
-
- n = 0;
- if(Details.centre || Details.rightJustify)
- x = 0.0f;
- else
- x = xstart;
- y = ystart;
-
- while(*s){
- if(x + GetStringWidth(s) > (Details.centre ? Details.centreSize : Details.wrapX)){
- // reached end of line
- if(Details.centre || Details.rightJustify)
- x = 0.0f;
- else
- x = xstart;
- n++;
- // Why even?
- y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY;
- }else{
- // still space in current line
- t = GetNextSpace(s);
- if(*t == '\0'){
- // end of string
- x += GetStringWidth(s);
- n++;
- s = t;
- }else{
- x += GetStringWidth(s);
- x += GetCharacterSize(*t - ' ');
- s = t+1;
- }
- }
- }
-
- return n;
-}
-
-void
-CFont::GetTextRect(CRect *rect, float xstart, float ystart, uint16 *s)
-{
- int numLines;
- float x, y;
- int16 maxlength;
- uint16 *t;
-
- maxlength = 0;
- numLines = 0;
- if(Details.centre || Details.rightJustify)
- x = 0.0f;
- else
- x = xstart;
- y = ystart;
-
- while(*s){
- if(x + GetStringWidth(s) > (Details.centre ? Details.centreSize : Details.wrapX)){
- // reached end of line
- if(x > maxlength)
- maxlength = x;
- if(Details.centre || Details.rightJustify)
- x = 0.0f;
- else
- x = xstart;
- numLines++;
- y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY;
- }else{
- // still space in current line
- t = GetNextSpace(s);
- if(*t == '\0'){
- // end of string
- x += GetStringWidth(s);
- if(x > maxlength)
- maxlength = x;
- numLines++;
- s = t;
- }else{
- x += GetStringWidth(s);
- x += GetCharacterSize(*t - ' ');
- s = t+1;
- }
- }
- }
-
- if(Details.centre){
- if(Details.backgroundOnlyText){
- rect->left = xstart - maxlength/2 - 4.0f;
- rect->right = xstart + maxlength/2 + 4.0f;
- rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines +
- ystart + 2.0f;
- rect->top = ystart - 2.0f;
- }else{
- rect->left = xstart - Details.centreSize*0.5f - 4.0f;
- rect->right = xstart + Details.centreSize*0.5f + 4.0f;
- rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines +
- ystart + 2.0f;
- rect->top = ystart - 2.0f;
- }
- }else{
- rect->left = xstart - 4.0f;
- rect->right = Details.wrapX;
- // WTF?
- rect->bottom = ystart - 4.0f + 4.0f;
- rect->top = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines +
- ystart + 2.0f + 2.0f;
- }
-}
-
-void
-CFont::PrintString(float x, float y, uint16 *start, uint16 *end, float spwidth)
-{
- uint16 *s, c, unused;
-
- for(s = start; s < end; s++){
- if(*s == '~')
- s = ParseToken(s, &unused);
- c = *s - ' ';
- if(Details.slant != 0.0f)
- y = (Details.slantRefX - x)*Details.slant + Details.slantRefY;
- PrintChar(x, y, c);
- x += GetCharacterSize(c);
- if(c == 0) // space
- x += spwidth;
- }
-}
-
-float
-CFont::GetCharacterWidth(uint16 c)
-{
- if(Details.proportional)
- return Size[Details.style][c];
- else
- return Size[Details.style][192];
-}
-
-float
-CFont::GetCharacterSize(uint16 c)
-{
- if(Details.proportional)
- return Size[Details.style][c] * Details.scaleX;
- else
- return Size[Details.style][192] * Details.scaleX;
-}
-
-float
-CFont::GetStringWidth(uint16 *s, bool spaces)
-{
- float w;
-
- w = 0.0f;
- for(; (*s != ' ' || spaces) && *s != '\0'; s++){
- if(*s == '~'){
- s++;
- while(*s != '~') s++;
- s++;
- if(*s == ' ' && !spaces)
- break;
- }
- w += GetCharacterSize(*s - ' ');
- }
- return w;
-}
-
-uint16*
-CFont::GetNextSpace(uint16 *s)
-{
- for(; *s != ' ' && *s != '\0'; s++)
- if(*s == '~'){
- s++;
- while(*s != '~') s++;
- s++;
- if(*s == ' ')
- break;
- }
- return s;
-}
-
-uint16*
-CFont::ParseToken(uint16 *s, uint16*)
-{
- s++;
- if(Details.color.r || Details.color.g || Details.color.b)
- switch(*s){
- case 'N':
- case 'n':
- NewLine = 1;
- break;
- case 'b': SetColor(CRGBA(0x80, 0xA7, 0xF3, 0xFF)); break;
- case 'g': SetColor(CRGBA(0x5F, 0xA0, 0x6A, 0xFF)); break;
- case 'h': SetColor(CRGBA(0xE1, 0xE1, 0xE1, 0xFF)); break;
- case 'l': SetColor(CRGBA(0x00, 0x00, 0x00, 0xFF)); break;
- case 'p': SetColor(CRGBA(0xA8, 0x6E, 0xFC, 0xFF)); break;
- case 'r': SetColor(CRGBA(0x71, 0x2B, 0x49, 0xFF)); break;
- case 'w': SetColor(CRGBA(0xAF, 0xAF, 0xAF, 0xFF)); break;
- case 'y': SetColor(CRGBA(0xD2, 0xC4, 0x6A, 0xFF)); break;
- }
- while(*s != '~') s++;
- return s+1;
-}
-
-void
-CFont::DrawFonts(void)
-{
- CSprite2d::DrawBank(Details.bank);
- CSprite2d::DrawBank(Details.bank+1);
- CSprite2d::DrawBank(Details.bank+2);
-}
-
-uint16
-CFont::character_code(uint8 c)
-{
- if(c < 128)
- return c;
- return foreign_table[c-128];
-}
-
-STARTPATCHES
-
- InjectHook(0x500A40, CFont::Initialise, PATCH_JUMP);
- InjectHook(0x500BA0, CFont::Shutdown, PATCH_JUMP);
- InjectHook(0x500BE0, CFont::InitPerFrame, PATCH_JUMP);
- InjectHook(0x500C30, CFont::PrintChar, PATCH_JUMP);
- InjectHook(0x500F50, (void (*)(float, float, uint16*))CFont::PrintString, PATCH_JUMP);
- InjectHook(0x501260, CFont::GetNumberLines, PATCH_JUMP);
- InjectHook(0x5013B0, CFont::GetTextRect, PATCH_JUMP);
- InjectHook(0x501730, (void (*)(float, float, uint16*, uint16*, float))CFont::PrintString, PATCH_JUMP);
- InjectHook(0x5017E0, CFont::GetCharacterWidth, PATCH_JUMP);
- InjectHook(0x501840, CFont::GetCharacterSize, PATCH_JUMP);
- InjectHook(0x5018A0, CFont::GetStringWidth, PATCH_JUMP);
- InjectHook(0x501960, CFont::GetNextSpace, PATCH_JUMP);
- InjectHook(0x5019A0, CFont::ParseToken, PATCH_JUMP);
- InjectHook(0x501B50, CFont::DrawFonts, PATCH_JUMP);
- InjectHook(0x501E80, CFont::character_code, PATCH_JUMP);
-
- InjectHook(0x501B80, CFont::SetScale, PATCH_JUMP);
- InjectHook(0x501BA0, CFont::SetSlantRefPoint, PATCH_JUMP);
- InjectHook(0x501BC0, CFont::SetSlant, PATCH_JUMP);
- InjectHook(0x501BD0, CFont::SetColor, PATCH_JUMP);
- InjectHook(0x501C60, CFont::SetJustifyOn, PATCH_JUMP);
- InjectHook(0x501C80, CFont::SetJustifyOff, PATCH_JUMP);
- InjectHook(0x501C90, CFont::SetCentreOn, PATCH_JUMP);
- InjectHook(0x501CB0, CFont::SetCentreOff, PATCH_JUMP);
- InjectHook(0x501CC0, CFont::SetWrapx, PATCH_JUMP);
- InjectHook(0x501CD0, CFont::SetCentreSize, PATCH_JUMP);
- InjectHook(0x501CE0, CFont::SetBackgroundOn, PATCH_JUMP);
- InjectHook(0x501CF0, CFont::SetBackgroundOff, PATCH_JUMP);
- InjectHook(0x501D00, CFont::SetBackgroundColor, PATCH_JUMP);
- InjectHook(0x501D30, CFont::SetBackGroundOnlyTextOn, PATCH_JUMP);
- InjectHook(0x501D40, CFont::SetBackGroundOnlyTextOff, PATCH_JUMP);
- InjectHook(0x501D50, CFont::SetRightJustifyOn, PATCH_JUMP);
- InjectHook(0x501D70, CFont::SetRightJustifyOff, PATCH_JUMP);
- InjectHook(0x501D90, CFont::SetPropOff, PATCH_JUMP);
- InjectHook(0x501DA0, CFont::SetPropOn, PATCH_JUMP);
- InjectHook(0x501DB0, CFont::SetFontStyle, PATCH_JUMP);
- InjectHook(0x501DC0, CFont::SetRightJustifyWrap, PATCH_JUMP);
- InjectHook(0x501DD0, CFont::SetAlphaFade, PATCH_JUMP);
- InjectHook(0x501DE0, CFont::SetDropColor, PATCH_JUMP);
- InjectHook(0x501E70, CFont::SetDropShadowPosition, PATCH_JUMP);
-
-ENDPATCHES
+#include "common.h"
+#include "patcher.h"
+#include "Sprite2d.h"
+#include "TxdStore.h"
+#include "Font.h"
+
+CFontDetails &CFont::Details = *(CFontDetails*)0x8F317C;
+int16 &CFont::NewLine = *(int16*)0x95CC94;
+CSprite2d *CFont::Sprite = (CSprite2d*)0x95CC04;
+
+#ifdef MORE_LANGUAGES
+uint8 CFont::LanguageSet = FONT_LANGSET_EFIGS;
+int32 CFont::Slot = -1;
+
+int16 CFont::Size[2][3][193] = {
+ {
+#else
+int16 CFont::Size[3][193] = {
+#endif
+ {
+ 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17, 13, 31,
+ 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10, 35, 26, 26, 26, 26,
+ 30, 26, 24, 23, 24, 22, 21, 24, 26, 10, 20, 26, 22, 29, 26, 25,
+ 23, 25, 24, 24, 22, 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37,
+ 35, 21, 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21, 21,
+ 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 33, 33, 33, 33, 35,
+ 27, 27, 27, 27, 32, 24, 23, 23, 23, 23, 11, 11, 11, 11, 26, 26,
+ 26, 26, 26, 26, 26, 25, 26, 21, 21, 21, 21, 32, 23, 22, 22, 22,
+ 22, 11, 11, 11, 11, 22, 22, 22, 22, 22, 22, 22, 22, 26, 21, 24,
+ 12, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 18, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+ 20
+ },
+
+ {
+ 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11, 17, 13, 33,
+ 28, 14, 22, 21, 24, 23, 23, 21, 23, 22, 10, 35, 13, 35, 13, 33,
+ 5, 25, 22, 23, 24, 21, 21, 24, 24, 9, 20, 24, 21, 27, 25, 25,
+ 22, 25, 23, 20, 23, 23, 23, 31, 23, 23, 23, 37, 33, 37, 35, 37,
+ 35, 21, 19, 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21,
+ 20, 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33, 33, 35,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 16
+ },
+
+ {
+ 15, 14, 16, 25, 19, 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27,
+ 19, 18, 19, 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35,
+ 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29, 19, 20,
+ 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19, 33, 31, 39, 37, 39,
+ 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23, 23,
+ 20, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35, 35, 35, 35, 37,
+ 19, 19, 19, 19, 29, 19, 19, 19, 19, 19, 9, 9, 9, 9, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 30, 19, 19, 19, 19,
+ 19, 10, 10, 10, 10, 19, 19, 19, 19, 19, 19, 19, 19, 19, 23, 35,
+ 12, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 11, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19
+ }
+#ifdef MORE_LANGUAGES
+ },
+ {
+ { 13, 12, 31, 35, 23, 35, 31, 9, 14, 15, 25, 30, 11, 17,
+ 13, 31, 23, 16, 22, 21, 24, 23, 23, 20, 23, 22, 10,
+ 35, 26, 26, 26, 26, 30, 26, 24, 23, 24, 22, 21, 24,
+ 26, 10, 20, 26, 22, 29, 26, 25, 23, 25, 24, 24, 22,
+ 25, 24, 29, 29, 23, 25, 37, 22, 37, 35, 37, 35, 21,
+ 22, 21, 21, 22, 13, 22, 21, 10, 16, 22, 11, 32, 21,
+ 21, 23, 22, 16, 20, 14, 21, 20, 30, 25, 21, 21, 13,
+ 33, 13, 13, 13, 24, 22, 22, 19, 26, 21, 30, 20, 23,
+ 23, 21, 24, 26, 23, 22, 23, 21, 22, 20, 20, 26, 25,
+ 24, 22, 31, 32, 23, 30, 22, 22, 32, 23, 19, 18, 18,
+ 15, 22, 19, 27, 19, 20, 20, 18, 22, 24, 20, 19, 19,
+ 20, 19, 16, 19, 28, 20, 20, 18, 26, 27, 19, 26, 18,
+ 19, 27, 19, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 18, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+ 26, 26, 26, 26, 26, 26, 26, 26, 26, 20 },
+ { 13, 9, 21, 35, 23, 35, 35, 11, 35, 35, 25, 35, 11,
+ 17, 13, 33, 28, 14, 22, 21, 24, 23, 23, 21, 23, 22,
+ 10, 35, 13, 35, 13, 33, 5, 25, 22, 23, 24, 21, 21, 24,
+ 24, 9, 20, 24, 21, 27, 25, 25, 22, 25, 23, 20, 23, 23,
+ 23, 31, 23, 23, 23, 37, 33, 37, 35, 37, 35, 21, 19,
+ 19, 21, 19, 17, 21, 21, 8, 17, 18, 14, 24, 21, 21, 20,
+ 22, 19, 20, 20, 19, 20, 26, 21, 20, 21, 33, 33, 33,
+ 33, 35, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 16, },
+ { 15, 14, 16, 25, 19,
+ 26, 22, 11, 18, 18, 27, 26, 13, 19, 9, 27, 19, 18, 19,
+ 19, 22, 19, 20, 18, 19, 20, 12, 32, 15, 32, 15, 35,
+ 15, 19, 19, 19, 19, 19, 16, 19, 20, 9, 19, 20, 14, 29,
+ 19, 20, 19, 19, 19, 19, 21, 19, 20, 32, 20, 19, 19,
+ 33, 31, 39, 37, 39, 37, 21, 21, 21, 23, 21, 19, 23, 23, 10, 19, 20, 16, 26, 23,
+ 21, 21, 20, 20, 22, 21, 22, 22, 26, 22, 22, 23, 35,
+ 35, 35, 35, 37, 19, 19, 19, 19, 19, 19, 29, 19, 19,
+ 19, 20, 22, 31, 19, 19, 19, 19, 19, 29, 19, 29, 19,
+ 21, 19, 30, 31, 21, 29, 19, 19, 29, 19, 21, 23, 32,
+ 21, 21, 30, 31, 22, 21, 32, 33, 23, 32, 21, 21, 32,
+ 21, 19, 19, 30, 31, 22, 22, 21, 32, 33, 23, 32, 21,
+ 21, 32, 21, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 11, 19, 19, 19, 19, 19, 19, 19, 19, 19,
+ 19, 19, 19, 19, 19, 19, 19, 19, 19, 19 },
+ }
+#endif
+};
+
+wchar foreign_table[128] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 176, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 177, 0, 0, 0, 0, 0, 95, 0, 0, 0, 0, 175,
+ 128, 129, 130, 0, 131, 0, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
+ 0, 173, 142, 143, 144, 0, 145, 0, 0, 146, 147, 148, 149, 0, 0, 150,
+ 151, 152, 153, 0, 154, 0, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
+ 0, 174, 165, 166, 167, 0, 168, 0, 0, 169, 170, 171, 172, 0, 0, 0,
+};
+
+void
+CFont::Initialise(void)
+{
+ int slot;
+
+ slot = CTxdStore::AddTxdSlot("fonts");
+#ifdef MORE_LANGUAGES
+ Slot = slot;
+ switch (LanguageSet)
+ {
+ case FONT_LANGSET_EFIGS:
+ default:
+ CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD");
+ break;
+ case FONT_LANGSET_RUSSIAN:
+ CTxdStore::LoadTxd(slot, "MODELS/FONTS_R.TXD");
+ break;
+ }
+#else
+ CTxdStore::LoadTxd(slot, "MODELS/FONTS.TXD");
+#endif
+ CTxdStore::AddRef(slot);
+ CTxdStore::PushCurrentTxd();
+ CTxdStore::SetCurrentTxd(slot);
+ Sprite[0].SetTexture("font2", "font2_mask");
+ Sprite[1].SetTexture("pager", "pager_mask");
+ Sprite[2].SetTexture("font1", "font1_mask");
+ SetScale(1.0f, 1.0f);
+ SetSlantRefPoint(SCREEN_WIDTH, 0.0f);
+ SetSlant(0.0f);
+ SetColor(CRGBA(0xFF, 0xFF, 0xFF, 0));
+ SetJustifyOff();
+ SetCentreOff();
+ SetWrapx(640.0f);
+ SetCentreSize(640.0f);
+ SetBackgroundOff();
+ SetBackgroundColor(CRGBA(0x80, 0x80, 0x80, 0x80));
+ SetBackGroundOnlyTextOff();
+ SetPropOn();
+ SetFontStyle(FONT_BANK);
+ SetRightJustifyWrap(0.0f);
+ SetAlphaFade(255.0f);
+ SetDropShadowPosition(0);
+ CTxdStore::PopCurrentTxd();
+}
+
+#ifdef MORE_LANGUAGES
+void
+CFont::ReloadFonts(uint8 set)
+{
+ if (Slot != -1 && LanguageSet != set) {
+ Sprite[0].Delete();
+ Sprite[1].Delete();
+ Sprite[2].Delete();
+ CTxdStore::PushCurrentTxd();
+ CTxdStore::RemoveTxd(Slot);
+ switch (set)
+ {
+ case FONT_LANGSET_EFIGS:
+ default:
+ CTxdStore::LoadTxd(Slot, "MODELS/FONTS.TXD");
+ break;
+ case FONT_LANGSET_RUSSIAN:
+ CTxdStore::LoadTxd(Slot, "MODELS/FONTS_R.TXD");
+ break;
+ }
+ CTxdStore::SetCurrentTxd(Slot);
+ Sprite[0].SetTexture("font2", "font2_mask");
+ Sprite[1].SetTexture("pager", "pager_mask");
+ Sprite[2].SetTexture("font1", "font1_mask");
+ CTxdStore::PopCurrentTxd();
+ }
+ LanguageSet = set;
+}
+#endif
+
+void
+CFont::Shutdown(void)
+{
+ Sprite[0].Delete();
+ Sprite[1].Delete();
+ Sprite[2].Delete();
+#ifdef MORE_LANGUAGES
+ CTxdStore::RemoveTxdSlot(Slot);
+ Slot = -1;
+#else
+ CTxdStore::RemoveTxdSlot(CTxdStore::FindTxdSlot("fonts"));
+#endif
+}
+
+void
+CFont::InitPerFrame(void)
+{
+ Details.bank = CSprite2d::GetBank(30, Sprite[0].m_pTexture);
+ CSprite2d::GetBank(15, Sprite[1].m_pTexture);
+ CSprite2d::GetBank(15, Sprite[2].m_pTexture);
+ SetDropShadowPosition(0);
+ NewLine = 0;
+}
+
+void
+CFont::PrintChar(float x, float y, wchar c)
+{
+ if(x <= 0.0f || x > SCREEN_WIDTH ||
+ y <= 0.0f || y > SCREEN_HEIGHT) // BUG: game uses SCREENW again
+ return;
+
+ float w = GetCharacterWidth(c) / 32.0f;
+ float xoff = c & 0xF;
+ float yoff = c >> 4;
+
+ if(Details.style == FONT_BANK || Details.style == FONT_HEADING){
+ if(Details.dropShadowPosition != 0){
+ CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank
+ CRect(x + SCREEN_SCALE_X(Details.dropShadowPosition),
+ y + SCREEN_SCALE_Y(Details.dropShadowPosition),
+ x + SCREEN_SCALE_X(Details.dropShadowPosition) + 32.0f * Details.scaleX * 1.0f,
+ y + SCREEN_SCALE_Y(Details.dropShadowPosition) + 40.0f * Details.scaleY * 0.5f),
+ Details.dropColor,
+ xoff/16.0f, yoff/12.8f,
+ (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f,
+ xoff/16.0f, (yoff+1.0f)/12.8f,
+ (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.0001f);
+ }
+ CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank
+ CRect(x, y,
+ x + 32.0f * Details.scaleX * 1.0f,
+ y + 40.0f * Details.scaleY * 0.5f),
+ Details.color,
+ xoff/16.0f, yoff/12.8f,
+ (xoff+1.0f)/16.0f - 0.001f, yoff/12.8f,
+ xoff/16.0f, (yoff+1.0f)/12.8f - 0.002f,
+ (xoff+1.0f)/16.0f - 0.001f, (yoff+1.0f)/12.8f - 0.002f);
+ }else{
+ CSprite2d::AddSpriteToBank(Details.bank + Details.style, // BUG: game doesn't add bank
+ CRect(x, y,
+ x + 32.0f * Details.scaleX * w,
+ y + 32.0f * Details.scaleY * 0.5f),
+ Details.color,
+ xoff/16.0f, yoff/16.0f,
+ (xoff+w)/16.0f, yoff/16.0f,
+ xoff/16.0f, (yoff+1.0f)/16.0f,
+ (xoff+w)/16.0f - 0.0001f, (yoff+1.0f)/16.0f - 0.0001f);
+ }
+}
+
+void
+CFont::PrintString(float xstart, float ystart, wchar *s)
+{
+ CRect rect;
+ int numSpaces;
+ float lineLength;
+ float x, y;
+ bool first;
+ wchar *start, *t;
+
+ if(*s == '*')
+ return;
+
+ if(Details.background){
+ GetNumberLines(xstart, ystart, s); // BUG: result not used
+ GetTextRect(&rect, xstart, ystart, s);
+ CSprite2d::DrawRect(rect, Details.backgroundColor);
+ }
+
+ lineLength = 0.0f;
+ numSpaces = 0;
+ first = true;
+ if(Details.centre || Details.rightJustify)
+ x = 0.0f;
+ else
+ x = xstart;
+ y = ystart;
+ start = s;
+
+ // This is super ugly, I blame R*
+ for(;;){
+ for(;;){
+ for(;;){
+ if(*s == '\0')
+ return;
+ int xend = Details.centre ? Details.centreSize :
+ Details.rightJustify ? xstart - Details.rightJustifyWrap :
+ Details.wrapX;
+ if(x + GetStringWidth(s) > xend && !first){
+ // flush line
+ float spaceWidth = !Details.justify || Details.centre ? 0.0f :
+ (Details.wrapX - lineLength) / numSpaces;
+ float xleft = Details.centre ? xstart - x/2 :
+ Details.rightJustify ? xstart - x :
+ xstart;
+ PrintString(xleft, y, start, s, spaceWidth);
+ // reset things
+ lineLength = 0.0f;
+ numSpaces = 0;
+ first = true;
+ if(Details.centre || Details.rightJustify)
+ x = 0.0f;
+ else
+ x = xstart;
+ y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY;
+ start = s;
+ }else
+ break;
+ }
+ // advance by one word
+ t = GetNextSpace(s);
+ if(t[0] == '\0' ||
+ t[0] == ' ' && t[1] == '\0')
+ break;
+ if(!first)
+ numSpaces++;
+ first = false;
+ x += GetStringWidth(s) + GetCharacterSize(*t - ' ');
+ lineLength = x;
+ s = t+1;
+ }
+ // print rest
+ if(t[0] == ' ' && t[1] == '\0')
+ t[0] = '\0';
+ x += GetStringWidth(s);
+ s = t;
+ float xleft = Details.centre ? xstart - x/2 :
+ Details.rightJustify ? xstart - x :
+ xstart;
+ PrintString(xleft, y, start, s, 0.0f);
+ }
+}
+
+int
+CFont::GetNumberLines(float xstart, float ystart, wchar *s)
+{
+ int n;
+ float x, y;
+ wchar *t;
+
+ n = 0;
+ if(Details.centre || Details.rightJustify)
+ x = 0.0f;
+ else
+ x = xstart;
+ y = ystart;
+
+ while(*s){
+ if(x + GetStringWidth(s) > (Details.centre ? Details.centreSize : Details.wrapX)){
+ // reached end of line
+ if(Details.centre || Details.rightJustify)
+ x = 0.0f;
+ else
+ x = xstart;
+ n++;
+ // Why even?
+ y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY;
+ }else{
+ // still space in current line
+ t = GetNextSpace(s);
+ if(*t == '\0'){
+ // end of string
+ x += GetStringWidth(s);
+ n++;
+ s = t;
+ }else{
+ x += GetStringWidth(s);
+ x += GetCharacterSize(*t - ' ');
+ s = t+1;
+ }
+ }
+ }
+
+ return n;
+}
+
+void
+CFont::GetTextRect(CRect *rect, float xstart, float ystart, wchar *s)
+{
+ int numLines;
+ float x, y;
+ int16 maxlength;
+ wchar *t;
+
+ maxlength = 0;
+ numLines = 0;
+ if(Details.centre || Details.rightJustify)
+ x = 0.0f;
+ else
+ x = xstart;
+ y = ystart;
+
+ while(*s){
+ if(x + GetStringWidth(s) > (Details.centre ? Details.centreSize : Details.wrapX)){
+ // reached end of line
+ if(x > maxlength)
+ maxlength = x;
+ if(Details.centre || Details.rightJustify)
+ x = 0.0f;
+ else
+ x = xstart;
+ numLines++;
+ y += 32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY;
+ }else{
+ // still space in current line
+ t = GetNextSpace(s);
+ if(*t == '\0'){
+ // end of string
+ x += GetStringWidth(s);
+ if(x > maxlength)
+ maxlength = x;
+ numLines++;
+ s = t;
+ }else{
+ x += GetStringWidth(s);
+ x += GetCharacterSize(*t - ' ');
+ s = t+1;
+ }
+ }
+ }
+
+ if(Details.centre){
+ if(Details.backgroundOnlyText){
+ rect->left = xstart - maxlength/2 - 4.0f;
+ rect->right = xstart + maxlength/2 + 4.0f;
+ rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines +
+ ystart + 2.0f;
+ rect->top = ystart - 2.0f;
+ }else{
+ rect->left = xstart - Details.centreSize*0.5f - 4.0f;
+ rect->right = xstart + Details.centreSize*0.5f + 4.0f;
+ rect->bottom = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines +
+ ystart + 2.0f;
+ rect->top = ystart - 2.0f;
+ }
+ }else{
+ rect->left = xstart - 4.0f;
+ rect->right = Details.wrapX;
+ // WTF?
+ rect->bottom = ystart - 4.0f + 4.0f;
+ rect->top = (32.0f * CFont::Details.scaleY * 0.5f + 2.0f * CFont::Details.scaleY) * numLines +
+ ystart + 2.0f + 2.0f;
+ }
+}
+
+void
+CFont::PrintString(float x, float y, wchar *start, wchar *end, float spwidth)
+{
+ wchar *s, c, unused;
+
+ for(s = start; s < end; s++){
+ if(*s == '~')
+ s = ParseToken(s, &unused);
+ c = *s - ' ';
+ if(Details.slant != 0.0f)
+ y = (Details.slantRefX - x)*Details.slant + Details.slantRefY;
+ PrintChar(x, y, c);
+ x += GetCharacterSize(c);
+ if(c == 0) // space
+ x += spwidth;
+ }
+}
+
+float
+CFont::GetCharacterWidth(wchar c)
+{
+#ifdef MORE_LANGUAGES
+ if (Details.proportional)
+ return Size[LanguageSet][Details.style][c];
+ else
+ return Size[LanguageSet][Details.style][192];
+#else
+ if (Details.proportional)
+ return Size[Details.style][c];
+ else
+ return Size[Details.style][192];
+#endif // MORE_LANGUAGES
+}
+
+float
+CFont::GetCharacterSize(wchar c)
+{
+#ifdef MORE_LANGUAGES
+ if(Details.proportional)
+ return Size[LanguageSet][Details.style][c] * Details.scaleX;
+ else
+ return Size[LanguageSet][Details.style][192] * Details.scaleX;
+#else
+ if (Details.proportional)
+ return Size[Details.style][c] * Details.scaleX;
+ else
+ return Size[Details.style][192] * Details.scaleX;
+#endif // MORE_LANGUAGES
+}
+
+float
+CFont::GetStringWidth(wchar *s, bool spaces)
+{
+ float w;
+
+ w = 0.0f;
+ for(; (*s != ' ' || spaces) && *s != '\0'; s++){
+ if(*s == '~'){
+ s++;
+ while(*s != '~') s++;
+ s++;
+ if(*s == ' ' && !spaces)
+ break;
+ }
+ w += GetCharacterSize(*s - ' ');
+ }
+ return w;
+}
+
+wchar*
+CFont::GetNextSpace(wchar *s)
+{
+ for(; *s != ' ' && *s != '\0'; s++)
+ if(*s == '~'){
+ s++;
+ while(*s != '~') s++;
+ s++;
+ if(*s == ' ')
+ break;
+ }
+ return s;
+}
+
+wchar*
+CFont::ParseToken(wchar *s, wchar*)
+{
+ s++;
+ if(Details.color.r || Details.color.g || Details.color.b)
+ switch(*s){
+ case 'N':
+ case 'n':
+ NewLine = 1;
+ break;
+ case 'b': SetColor(CRGBA(0x80, 0xA7, 0xF3, 0xFF)); break;
+ case 'g': SetColor(CRGBA(0x5F, 0xA0, 0x6A, 0xFF)); break;
+ case 'h': SetColor(CRGBA(0xE1, 0xE1, 0xE1, 0xFF)); break;
+ case 'l': SetColor(CRGBA(0x00, 0x00, 0x00, 0xFF)); break;
+ case 'p': SetColor(CRGBA(0xA8, 0x6E, 0xFC, 0xFF)); break;
+ case 'r': SetColor(CRGBA(0x71, 0x2B, 0x49, 0xFF)); break;
+ case 'w': SetColor(CRGBA(0xAF, 0xAF, 0xAF, 0xFF)); break;
+ case 'y': SetColor(CRGBA(0xD2, 0xC4, 0x6A, 0xFF)); break;
+ }
+ while(*s != '~') s++;
+ return s+1;
+}
+
+void
+CFont::DrawFonts(void)
+{
+ CSprite2d::DrawBank(Details.bank);
+ CSprite2d::DrawBank(Details.bank+1);
+ CSprite2d::DrawBank(Details.bank+2);
+}
+
+wchar
+CFont::character_code(uint8 c)
+{
+ if(c < 128)
+ return c;
+ return foreign_table[c-128];
+}
+
+STARTPATCHES
+
+ InjectHook(0x500A40, CFont::Initialise, PATCH_JUMP);
+ InjectHook(0x500BA0, CFont::Shutdown, PATCH_JUMP);
+ InjectHook(0x500BE0, CFont::InitPerFrame, PATCH_JUMP);
+ InjectHook(0x500C30, CFont::PrintChar, PATCH_JUMP);
+ InjectHook(0x500F50, (void (*)(float, float, wchar*))CFont::PrintString, PATCH_JUMP);
+ InjectHook(0x501260, CFont::GetNumberLines, PATCH_JUMP);
+ InjectHook(0x5013B0, CFont::GetTextRect, PATCH_JUMP);
+ InjectHook(0x501730, (void (*)(float, float, wchar*, wchar*, float))CFont::PrintString, PATCH_JUMP);
+ InjectHook(0x5017E0, CFont::GetCharacterWidth, PATCH_JUMP);
+ InjectHook(0x501840, CFont::GetCharacterSize, PATCH_JUMP);
+ InjectHook(0x5018A0, CFont::GetStringWidth, PATCH_JUMP);
+ InjectHook(0x501960, CFont::GetNextSpace, PATCH_JUMP);
+ InjectHook(0x5019A0, CFont::ParseToken, PATCH_JUMP);
+ InjectHook(0x501B50, CFont::DrawFonts, PATCH_JUMP);
+ InjectHook(0x501E80, CFont::character_code, PATCH_JUMP);
+
+ InjectHook(0x501B80, CFont::SetScale, PATCH_JUMP);
+ InjectHook(0x501BA0, CFont::SetSlantRefPoint, PATCH_JUMP);
+ InjectHook(0x501BC0, CFont::SetSlant, PATCH_JUMP);
+ InjectHook(0x501BD0, CFont::SetColor, PATCH_JUMP);
+ InjectHook(0x501C60, CFont::SetJustifyOn, PATCH_JUMP);
+ InjectHook(0x501C80, CFont::SetJustifyOff, PATCH_JUMP);
+ InjectHook(0x501C90, CFont::SetCentreOn, PATCH_JUMP);
+ InjectHook(0x501CB0, CFont::SetCentreOff, PATCH_JUMP);
+ InjectHook(0x501CC0, CFont::SetWrapx, PATCH_JUMP);
+ InjectHook(0x501CD0, CFont::SetCentreSize, PATCH_JUMP);
+ InjectHook(0x501CE0, CFont::SetBackgroundOn, PATCH_JUMP);
+ InjectHook(0x501CF0, CFont::SetBackgroundOff, PATCH_JUMP);
+ InjectHook(0x501D00, CFont::SetBackgroundColor, PATCH_JUMP);
+ InjectHook(0x501D30, CFont::SetBackGroundOnlyTextOn, PATCH_JUMP);
+ InjectHook(0x501D40, CFont::SetBackGroundOnlyTextOff, PATCH_JUMP);
+ InjectHook(0x501D50, CFont::SetRightJustifyOn, PATCH_JUMP);
+ InjectHook(0x501D70, CFont::SetRightJustifyOff, PATCH_JUMP);
+ InjectHook(0x501D90, CFont::SetPropOff, PATCH_JUMP);
+ InjectHook(0x501DA0, CFont::SetPropOn, PATCH_JUMP);
+ InjectHook(0x501DB0, CFont::SetFontStyle, PATCH_JUMP);
+ InjectHook(0x501DC0, CFont::SetRightJustifyWrap, PATCH_JUMP);
+ InjectHook(0x501DD0, CFont::SetAlphaFade, PATCH_JUMP);
+ InjectHook(0x501DE0, CFont::SetDropColor, PATCH_JUMP);
+ InjectHook(0x501E70, CFont::SetDropShadowPosition, PATCH_JUMP);
+
+ENDPATCHES
diff --git a/src/render/Font.h b/src/render/Font.h
index 132ad168..0659dda1 100644
--- a/src/render/Font.h
+++ b/src/render/Font.h
@@ -39,9 +39,23 @@ enum {
ALIGN_RIGHT,
};
+#ifdef MORE_LANGUAGES
+enum
+{
+ FONT_LANGSET_EFIGS,
+ FONT_LANGSET_RUSSIAN
+};
+#endif
+
class CFont
{
+#ifdef MORE_LANGUAGES
+ static int16 Size[2][3][193];
+ static uint8 LanguageSet;
+ static int32 Slot;
+#else
static int16 Size[3][193];
+#endif
static int16 &NewLine;
static CSprite2d *Sprite; //[3]
public:
@@ -50,18 +64,18 @@ public:
static void Initialise(void);
static void Shutdown(void);
static void InitPerFrame(void);
- static void PrintChar(float x, float y, uint16 c);
- static void PrintString(float x, float y, uint16 *s);
- static int GetNumberLines(float xstart, float ystart, uint16 *s);
- static void GetTextRect(CRect *rect, float xstart, float ystart, uint16 *s);
- static void PrintString(float x, float y, uint16 *start, uint16 *end, float spwidth);
- static float GetCharacterWidth(uint16 c);
- static float GetCharacterSize(uint16 c);
- static float GetStringWidth(uint16 *s, bool spaces = false);
- static uint16 *GetNextSpace(uint16 *s);
- static uint16 *ParseToken(uint16 *s, uint16*);
+ static void PrintChar(float x, float y, wchar c);
+ static void PrintString(float x, float y, wchar *s);
+ static int GetNumberLines(float xstart, float ystart, wchar *s);
+ static void GetTextRect(CRect *rect, float xstart, float ystart, wchar *s);
+ static void PrintString(float x, float y, wchar *start, wchar *end, float spwidth);
+ static float GetCharacterWidth(wchar c);
+ static float GetCharacterSize(wchar c);
+ static float GetStringWidth(wchar *s, bool spaces = false);
+ static wchar *GetNextSpace(wchar *s);
+ static wchar *ParseToken(wchar *s, wchar*);
static void DrawFonts(void);
- static uint16 character_code(uint8 c);
+ static wchar character_code(uint8 c);
static CFontDetails GetDetails() { return Details; }
static void SetScale(float x, float y) { Details.scaleX = x; Details.scaleY = y; }
@@ -136,4 +150,6 @@ public:
if(Details.alphaFade < 255.0f)
Details.dropColor.a *= Details.alphaFade/255.0f;
}
+
+ static void ReloadFonts(uint8 set);
};
diff --git a/src/render/Glass.cpp b/src/render/Glass.cpp
index ac04032b..41d31985 100644
--- a/src/render/Glass.cpp
+++ b/src/render/Glass.cpp
@@ -1,21 +1,721 @@
#include "common.h"
#include "patcher.h"
#include "Glass.h"
+#include "Timer.h"
+#include "Object.h"
+#include "General.h"
+#include "AudioScriptObject.h"
+#include "World.h"
+#include "TimeCycle.h"
+#include "Particle.h"
+#include "Camera.h"
+#include "RenderBuffer.h"
+#include "Shadows.h"
+#include "ModelIndices.h"
+#include "main.h"
-WRAPPER void CGlass::AskForObjectToBeRenderedInGlass(CEntity *ent) { EAXJMP(0x5033F0); }
-WRAPPER void
-CGlass::WindowRespondsToCollision(CEntity *ent, float amount, CVector speed, CVector point, bool foo)
+uint32 CGlass::NumGlassEntities;
+CEntity *CGlass::apEntitiesToBeRendered[NUM_GLASSENTITIES];
+CFallingGlassPane CGlass::aGlassPanes[NUM_GLASSPANES];
+
+
+CVector2D CentersWithTriangle[NUM_GLASSTRIANGLES];
+const CVector2D CoorsWithTriangle[NUM_GLASSTRIANGLES][3] =
+{
+ {
+ CVector2D(0.0f, 0.0f),
+ CVector2D(0.0f, 1.0f),
+ CVector2D(0.4f, 0.5f)
+ },
+
+ {
+ CVector2D(0.0f, 1.0f),
+ CVector2D(1.0f, 1.0f),
+ CVector2D(0.4f, 0.5f)
+ },
+
+ {
+ CVector2D(0.0f, 0.0f),
+ CVector2D(0.4f, 0.5f),
+ CVector2D(0.7f, 0.0f)
+ },
+
+ {
+ CVector2D(0.7f, 0.0f),
+ CVector2D(0.4f, 0.5f),
+ CVector2D(1.0f, 1.0f)
+ },
+
+ {
+ CVector2D(0.7f, 0.0f),
+ CVector2D(1.0f, 1.0f),
+ CVector2D(1.0f, 0.0f)
+ }
+};
+
+#define TEMPBUFFERVERTHILIGHTOFFSET 0
+#define TEMPBUFFERINDEXHILIGHTOFFSET 0
+#define TEMPBUFFERVERTHILIGHTSIZE 128
+#define TEMPBUFFERINDEXHILIGHTSIZE 512
+
+#define TEMPBUFFERVERTSHATTEREDOFFSET TEMPBUFFERVERTHILIGHTSIZE
+#define TEMPBUFFERINDEXSHATTEREDOFFSET TEMPBUFFERINDEXHILIGHTSIZE
+#define TEMPBUFFERVERTSHATTEREDSIZE 192
+#define TEMPBUFFERINDEXSHATTEREDSIZE 768
+
+#define TEMPBUFFERVERTREFLECTIONOFFSET TEMPBUFFERVERTSHATTEREDSIZE
+#define TEMPBUFFERINDEXREFLECTIONOFFSET TEMPBUFFERINDEXSHATTEREDSIZE
+#define TEMPBUFFERVERTREFLECTIONSIZE 256
+#define TEMPBUFFERINDEXREFLECTIONSIZE 1024
+
+int32 TempBufferIndicesStoredHiLight = 0;
+int32 TempBufferVerticesStoredHiLight = 0;
+int32 TempBufferIndicesStoredShattered = 0;
+int32 TempBufferVerticesStoredShattered = 0;
+int32 TempBufferIndicesStoredReflection = 0;
+int32 TempBufferVerticesStoredReflection = 0;
+
+void
+CFallingGlassPane::Update(void)
+{
+ if ( CTimer::GetTimeInMilliseconds() >= m_nTimer )
+ {
+ // Apply MoveSpeed
+ GetPosition() += m_vecMoveSpeed * CTimer::GetTimeStep();
+
+ // Apply Gravity
+ m_vecMoveSpeed.z -= 0.02f * CTimer::GetTimeStep();
+
+ // Apply TurnSpeed
+ GetRight() += CrossProduct(m_vecTurn, GetRight());
+ GetForward() += CrossProduct(m_vecTurn, GetForward());
+ GetUp() += CrossProduct(m_vecTurn, GetUp());
+
+ if ( GetPosition().z < m_fGroundZ )
+ {
+ CVector pos;
+ CVector dir;
+
+ m_bActive = false;
+
+ pos = CVector(GetPosition().x, GetPosition().y, m_fGroundZ);
+
+ PlayOneShotScriptObject(_SCRSOUND_GLASS_SHARD, pos);
+
+ RwRGBA color = { 255, 255, 255, 255 };
+
+ static int32 nFrameGen = 0;
+
+ for ( int32 i = 0; i < 4; i++ )
+ {
+ dir.x = CGeneral::GetRandomNumberInRange(-0.35f, 0.35f);
+ dir.y = CGeneral::GetRandomNumberInRange(-0.35f, 0.35f);
+ dir.z = CGeneral::GetRandomNumberInRange(0.05f, 0.20f);
+
+ CParticle::AddParticle(PARTICLE_CAR_DEBRIS,
+ pos,
+ dir,
+ nil,
+ CGeneral::GetRandomNumberInRange(0.02f, 0.2f),
+ color,
+ CGeneral::GetRandomNumberInRange(-40, 40),
+ 0,
+ ++nFrameGen & 3,
+ 500);
+ }
+ }
+ }
+}
+
+void
+CFallingGlassPane::Render(void)
+{
+ float distToCamera = (TheCamera.GetPosition() - GetPosition()).Magnitude();
+
+ CVector fwdNorm = GetForward();
+ fwdNorm.Normalise();
+ uint8 alpha = CGlass::CalcAlphaWithNormal(&fwdNorm);
+
+ int32 time = clamp(CTimer::GetTimeInMilliseconds() - m_nTimer, 0, 500);
+
+ uint8 color = int32( float(alpha) * (float(time) / 500) );
+
+ if ( TempBufferIndicesStoredHiLight >= TEMPBUFFERINDEXHILIGHTSIZE-7 || TempBufferVerticesStoredHiLight >= TEMPBUFFERVERTHILIGHTSIZE-4 )
+ CGlass::RenderHiLightPolys();
+
+ // HiLight Polys
+
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], color, color, color, color);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], color, color, color, color);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], color, color, color, color);
+
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], 0.5f);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], 0.5f);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], 0.5f);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], 0.6f);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], 0.6f);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], 0.6f);
+
+ ASSERT(m_nTriIndex < NUM_GLASSTRIANGLES);
+
+ CVector2D p0 = CoorsWithTriangle[m_nTriIndex][0] - CentersWithTriangle[m_nTriIndex];
+ CVector2D p1 = CoorsWithTriangle[m_nTriIndex][1] - CentersWithTriangle[m_nTriIndex];
+ CVector2D p2 = CoorsWithTriangle[m_nTriIndex][2] - CentersWithTriangle[m_nTriIndex];
+ CVector v0 = *this * CVector(p0.x, 0.0f, p0.y);
+ CVector v1 = *this * CVector(p1.x, 0.0f, p1.y);
+ CVector v2 = *this * CVector(p2.x, 0.0f, p2.y);
+
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 0], v0.x, v0.y, v0.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 1], v1.x, v1.y, v1.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredHiLight + 2], v2.x, v2.y, v2.z);
+
+ TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 0] = TempBufferVerticesStoredHiLight + 0;
+ TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 1] = TempBufferVerticesStoredHiLight + 1;
+ TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 2] = TempBufferVerticesStoredHiLight + 2;
+ TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 3] = TempBufferVerticesStoredHiLight + 0;
+ TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 4] = TempBufferVerticesStoredHiLight + 2;
+ TempBufferRenderIndexList[TempBufferIndicesStoredHiLight + 5] = TempBufferVerticesStoredHiLight + 1;
+
+ TempBufferVerticesStoredHiLight += 3;
+ TempBufferIndicesStoredHiLight += 6;
+
+ if ( m_bShattered )
+ {
+ if ( TempBufferIndicesStoredShattered >= TEMPBUFFERINDEXSHATTEREDSIZE-7 || TempBufferVerticesStoredShattered >= TEMPBUFFERVERTSHATTEREDSIZE-4 )
+ CGlass::RenderShatteredPolys();
+
+ uint8 shatteredColor = 255;
+ if ( distToCamera > 30.0f )
+ shatteredColor = int32((1.0f - (distToCamera - 30.0f) * 4.0f / 40.0f) * 255);
+
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], shatteredColor, shatteredColor, shatteredColor, shatteredColor);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], shatteredColor, shatteredColor, shatteredColor, shatteredColor);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], shatteredColor, shatteredColor, shatteredColor, shatteredColor);
+
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 4.0f * CoorsWithTriangle[m_nTriIndex][0].x * m_fStep);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 4.0f * CoorsWithTriangle[m_nTriIndex][0].y * m_fStep);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 4.0f * CoorsWithTriangle[m_nTriIndex][1].x * m_fStep);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 4.0f * CoorsWithTriangle[m_nTriIndex][1].y * m_fStep);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 4.0f * CoorsWithTriangle[m_nTriIndex][2].x * m_fStep);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 4.0f * CoorsWithTriangle[m_nTriIndex][2].y * m_fStep);
+
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], v0.x, v0.y, v0.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], v1.x, v1.y, v1.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], v2.x, v2.y, v2.z);
+
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 0] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 0;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 1] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 1;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 2] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 2;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 3] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 0;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 4] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 2;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 5] = TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET + 1;
+
+ TempBufferIndicesStoredShattered += 6;
+ TempBufferVerticesStoredShattered += 3;
+ }
+}
+
+void
+CGlass::Init(void)
+{
+ for ( int32 i = 0; i < NUM_GLASSPANES; i++ )
+ aGlassPanes[i].m_bActive = false;
+
+ for ( int32 i = 0; i < NUM_GLASSTRIANGLES; i++ )
+ CentersWithTriangle[i] = (CoorsWithTriangle[i][0] + CoorsWithTriangle[i][1] + CoorsWithTriangle[i][2]) / 3;
+}
+
+void
+CGlass::Update(void)
+{
+ for ( int32 i = 0; i < NUM_GLASSPANES; i++ )
+ {
+ if ( aGlassPanes[i].m_bActive )
+ aGlassPanes[i].Update();
+ }
+}
+
+void
+CGlass::Render(void)
+{
+ TempBufferVerticesStoredHiLight = 0;
+ TempBufferIndicesStoredHiLight = 0;
+
+ TempBufferVerticesStoredShattered = TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferIndicesStoredShattered = TEMPBUFFERINDEXSHATTEREDOFFSET;
+
+ TempBufferVerticesStoredReflection = TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferIndicesStoredReflection = TEMPBUFFERINDEXREFLECTIONOFFSET;
+
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE);
+ RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR);
+ RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE);
+ RwRenderStateSet(rwRENDERSTATEFOGCOLOR, (void *)RWRGBALONG(CTimeCycle::GetFogRed(), CTimeCycle::GetFogGreen(), CTimeCycle::GetFogBlue(), 255));
+ RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE);
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE);
+
+ for ( int32 i = 0; i < NUM_GLASSPANES; i++ )
+ {
+ if ( aGlassPanes[i].m_bActive )
+ aGlassPanes[i].Render();
+ }
+
+ for ( uint32 i = 0; i < NumGlassEntities; i++ )
+ RenderEntityInGlass(apEntitiesToBeRendered[i]);
+
+ NumGlassEntities = 0;
+
+ RenderHiLightPolys();
+ RenderShatteredPolys();
+ RenderReflectionPolys();
+
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE);
+ RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void *)TRUE);
+ RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
+ RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE);
+}
+
+CFallingGlassPane *
+CGlass::FindFreePane(void)
+{
+ for ( int32 i = 0; i < NUM_GLASSPANES; i++ )
+ {
+ if ( !aGlassPanes[i].m_bActive )
+ return &aGlassPanes[i];
+ }
+
+ return nil;
+}
+
+void
+CGlass::GeneratePanesForWindow(uint32 type, CVector pos, CVector up, CVector right, CVector speed, CVector point,
+ float moveSpeed, bool cracked, bool explosion)
+{
+ float upLen = up.Magnitude();
+ float rightLen = right.Magnitude();
+
+ float upSteps = upLen + 0.75f;
+ if ( upSteps < 1.0f ) upSteps = 1.0f;
+
+ float rightSteps = rightLen + 0.75f;
+ if ( rightSteps < 1.0f ) rightSteps = 1.0f;
+
+ uint32 ysteps = (uint32)upSteps;
+ if ( ysteps > 3 ) ysteps = 3;
+
+ uint32 xsteps = (uint32)rightSteps;
+ if ( xsteps > 3 ) xsteps = 3;
+
+ if ( explosion )
+ {
+ if ( ysteps > 1 ) ysteps = 1;
+ if ( xsteps > 1 ) xsteps = 1;
+ }
+
+ float upScl = upLen / float(ysteps);
+ float rightScl = rightLen / float(xsteps);
+
+ bool bZFound;
+ float groundZ = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, pos.z, &bZFound);
+ if ( !bZFound ) groundZ = pos.z - 2.0f;
+
+ for ( uint32 y = 0; y < ysteps; y++ )
+ {
+ for ( uint32 x = 0; x < xsteps; x++ )
+ {
+ float stepy = float(y) * upLen / float(ysteps);
+ float stepx = float(x) * rightLen / float(xsteps);
+
+ for ( int32 i = 0; i < NUM_GLASSTRIANGLES; i++ )
+ {
+ CFallingGlassPane *pane = FindFreePane();
+ if ( pane )
+ {
+ pane->m_nTriIndex = i;
+
+ pane->GetRight() = (right * rightScl) / rightLen;
+#ifdef FIX_BUGS
+ pane->GetUp() = (up * upScl) / upLen;
+#else
+ pane->GetUp() = (up * upScl) / rightLen; // copypaste bug
+#endif
+ CVector fwd = CrossProduct(pane->GetRight(), pane->GetUp());
+ fwd.Normalise();
+
+ pane->GetForward() = fwd;
+
+ pane->GetPosition() = right / rightLen * (rightScl * CentersWithTriangle[i].x + stepx)
+ + up / upLen * (upScl * CentersWithTriangle[i].y + stepy)
+ + pos;
+
+ pane->m_vecMoveSpeed.x = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0015f + speed.x;
+ pane->m_vecMoveSpeed.y = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.0015f + speed.y;
+ pane->m_vecMoveSpeed.z = 0.0f + speed.z;
+
+ if ( moveSpeed != 0.0f )
+ {
+ CVector dist = pane->GetPosition() - point;
+ dist.Normalise();
+
+ pane->m_vecMoveSpeed += moveSpeed * dist;
+ }
+
+ pane->m_vecTurn.x = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.002f;
+ pane->m_vecTurn.y = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.002f;
+ pane->m_vecTurn.z = float((CGeneral::GetRandomNumber() & 127) - 64) * 0.002f;
+
+ switch ( type )
+ {
+ case 0:
+ pane->m_nTimer = CTimer::GetTimeInMilliseconds();
+ break;
+ case 1:
+ float dist = (pane->GetPosition() - point).Magnitude();
+ pane->m_nTimer = uint32(dist*100 + CTimer::GetTimeInMilliseconds());
+ break;
+ }
+
+ pane->m_fGroundZ = groundZ;
+ pane->m_bShattered = cracked;
+ pane->m_fStep = upLen / float(ysteps);
+ pane->m_bActive = true;
+ }
+ }
+ }
+ }
+}
+
+void
+CGlass::AskForObjectToBeRenderedInGlass(CEntity *entity)
+{
+#ifdef FIX_BUGS
+ if ( NumGlassEntities < NUM_GLASSPANES )
+#else
+ if ( NumGlassEntities < NUM_GLASSPANES-1 )
+#endif
+ {
+ apEntitiesToBeRendered[NumGlassEntities++] = entity;
+ }
+}
+
+void
+CGlass::RenderEntityInGlass(CEntity *entity)
+{
+ CObject *object = (CObject *)entity;
+
+ if ( object->bGlassBroken )
+ return;
+
+ float distToCamera = (TheCamera.GetPosition() - object->GetPosition()).Magnitude();
+
+ if ( distToCamera > 40.0f )
+ return;
+
+ CVector fwdNorm = object->GetForward();
+ fwdNorm.Normalise();
+ uint8 alpha = CalcAlphaWithNormal(&fwdNorm);
+
+ CColModel *col = object->GetColModel();
+
+ if ( col->numTriangles >= 2 )
+ {
+ CVector a = object->GetMatrix() * col->vertices[0];
+ CVector b = object->GetMatrix() * col->vertices[1];
+ CVector c = object->GetMatrix() * col->vertices[2];
+ CVector d = object->GetMatrix() * col->vertices[3];
+
+ if ( object->bGlassCracked )
+ {
+ uint8 color = 255;
+ if ( distToCamera > 30.0f )
+ color = int32((1.0f - (distToCamera - 30.0f) * 4.0f / 40.0f) * 255);
+
+ if ( TempBufferIndicesStoredShattered >= TEMPBUFFERINDEXSHATTEREDSIZE-13 || TempBufferVerticesStoredShattered >= TEMPBUFFERVERTSHATTEREDSIZE-5 )
+ RenderShatteredPolys();
+
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], color, color, color, color);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], color, color, color, color);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], color, color, color, color);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], color, color, color, color);
+
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 0.0f);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], 0.0f);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 16.0f);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], 0.0f);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 0.0f);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], 16.0f);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], 16.0f);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], 16.0f);
+
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 0], a.x, a.y, a.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 1], b.x, b.y, b.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 2], c.x, c.y, c.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredShattered + 3], d.x, d.y, d.z);
+
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 0] = col->triangles[0].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 1] = col->triangles[0].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 2] = col->triangles[0].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 3] = col->triangles[1].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 4] = col->triangles[1].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 5] = col->triangles[1].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 6] = col->triangles[0].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 7] = col->triangles[0].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 8] = col->triangles[0].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 9] = col->triangles[1].a + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 10] = col->triangles[1].c + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredShattered + 11] = col->triangles[1].b + TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET;
+
+ TempBufferIndicesStoredShattered += 12;
+ TempBufferVerticesStoredShattered += 4;
+ }
+
+ if ( TempBufferIndicesStoredReflection >= TEMPBUFFERINDEXREFLECTIONSIZE-13 || TempBufferVerticesStoredReflection >= TEMPBUFFERVERTREFLECTIONSIZE-5 )
+ RenderReflectionPolys();
+
+ uint8 color = 100;
+ if ( distToCamera > 30.0f )
+ color = int32((1.0f - (distToCamera - 30.0f) * 4.0f / 40.0f) * 100);
+
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], color, color, color, color);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], color, color, color, color);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], color, color, color, color);
+ RwIm3DVertexSetRGBA (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], color, color, color, color);
+
+ float FwdAngle = CGeneral::GetATanOfXY(TheCamera.GetForward().x, TheCamera.GetForward().y);
+ float v = 2.0f * TheCamera.GetForward().z * 0.2f;
+ float u = float(object->m_randomSeed & 15) * 0.02f + (FwdAngle / TWOPI);
+
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], u);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], v);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], u+0.2f);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], v);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], u);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], v+0.2f);
+ RwIm3DVertexSetU (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], u+0.2f);
+ RwIm3DVertexSetV (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], v+0.2f);
+
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 0], a.x, a.y, a.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 1], b.x, b.y, b.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 2], c.x, c.y, c.z);
+ RwIm3DVertexSetPos (&TempBufferRenderVertices[TempBufferVerticesStoredReflection + 3], d.x, d.y, d.z);
+
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 0] = col->triangles[0].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 1] = col->triangles[0].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 2] = col->triangles[0].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 3] = col->triangles[1].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 4] = col->triangles[1].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 5] = col->triangles[1].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 6] = col->triangles[0].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 7] = col->triangles[0].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 8] = col->triangles[0].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 9] = col->triangles[1].a + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 10] = col->triangles[1].c + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+ TempBufferRenderIndexList[TempBufferIndicesStoredReflection + 11] = col->triangles[1].b + TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET;
+
+ TempBufferIndicesStoredReflection += 12;
+ TempBufferVerticesStoredReflection += 4;
+ }
+}
+
+int32
+CGlass::CalcAlphaWithNormal(CVector *normal)
{
- EAXJMP(0x503F10);
+ float fwdDir = 2.0f * DotProduct(*normal, TheCamera.GetForward());
+ float fwdDot = DotProduct(TheCamera.GetForward()-fwdDir*(*normal), CVector(0.57f, 0.57f, -0.57f));
+ return int32(lerp(fwdDot*fwdDot*fwdDot*fwdDot*fwdDot*fwdDot, 20.0f, 255.0f));
}
-WRAPPER void
-CGlass::WindowRespondsToSoftCollision(CEntity *ent, float amount)
+void
+CGlass::RenderHiLightPolys(void)
{
- EAXJMP(0x504630);
+ if ( TempBufferVerticesStoredHiLight != TEMPBUFFERVERTHILIGHTOFFSET )
+ {
+ RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE);
+ RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)RwTextureGetRaster(gpShadowExplosionTex));
+
+ LittleTest();
+
+ if ( RwIm3DTransform(TempBufferRenderVertices, TempBufferVerticesStoredHiLight, nil, rwIM3D_VERTEXUV) )
+ {
+ RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, TempBufferRenderIndexList, TempBufferIndicesStoredHiLight);
+ RwIm3DEnd();
+ }
+
+ TempBufferVerticesStoredHiLight = TEMPBUFFERVERTHILIGHTOFFSET;
+ TempBufferIndicesStoredHiLight = TEMPBUFFERINDEXHILIGHTOFFSET;
+ }
+}
+
+void
+CGlass::RenderShatteredPolys(void)
+{
+ if ( TempBufferVerticesStoredShattered != TEMPBUFFERVERTSHATTEREDOFFSET )
+ {
+ RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)RwTextureGetRaster(gpCrackedGlassTex));
+ RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
+
+ LittleTest();
+
+ if ( RwIm3DTransform(&TempBufferRenderVertices[TEMPBUFFERVERTSHATTEREDOFFSET], TempBufferVerticesStoredShattered - TEMPBUFFERVERTSHATTEREDOFFSET, nil, rwIM3D_VERTEXUV) )
+ {
+ RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, &TempBufferRenderIndexList[TEMPBUFFERINDEXSHATTEREDOFFSET], TempBufferIndicesStoredShattered - TEMPBUFFERINDEXSHATTEREDOFFSET);
+ RwIm3DEnd();
+ }
+
+ TempBufferIndicesStoredShattered = TEMPBUFFERINDEXSHATTEREDOFFSET;
+ TempBufferVerticesStoredShattered = TEMPBUFFERVERTSHATTEREDOFFSET;
+ }
+}
+
+void
+CGlass::RenderReflectionPolys(void)
+{
+ if ( TempBufferVerticesStoredReflection != TEMPBUFFERVERTREFLECTIONOFFSET )
+ {
+ RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)RwTextureGetRaster(gpShadowHeadLightsTex));
+ RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
+
+ LittleTest();
+
+ if ( RwIm3DTransform(&TempBufferRenderVertices[TEMPBUFFERVERTREFLECTIONOFFSET], TempBufferVerticesStoredReflection - TEMPBUFFERVERTREFLECTIONOFFSET, nil, rwIM3D_VERTEXUV) )
+ {
+ RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, &TempBufferRenderIndexList[TEMPBUFFERINDEXREFLECTIONOFFSET], TempBufferIndicesStoredReflection - TEMPBUFFERINDEXREFLECTIONOFFSET);
+ RwIm3DEnd();
+ }
+
+ TempBufferIndicesStoredReflection = TEMPBUFFERINDEXREFLECTIONOFFSET;
+ TempBufferVerticesStoredReflection = TEMPBUFFERVERTREFLECTIONOFFSET;
+ }
+}
+
+void
+CGlass::WindowRespondsToCollision(CEntity *entity, float amount, CVector speed, CVector point, bool explosion)
+{
+ CObject *object = (CObject *)entity;
+
+ if ( object->bGlassBroken )
+ return;
+
+ object->bGlassCracked = true;
+
+ CColModel *col = object->GetColModel();
+
+ CVector a = object->GetMatrix() * col->vertices[0];
+ CVector b = object->GetMatrix() * col->vertices[1];
+ CVector c = object->GetMatrix() * col->vertices[2];
+ CVector d = object->GetMatrix() * col->vertices[3];
+
+ float minx = min(min(a.x, b.x), min(c.x, d.x));
+ float maxx = max(max(a.x, b.x), max(c.x, d.x));
+ float miny = min(min(a.y, b.y), min(c.y, d.y));
+ float maxy = max(max(a.y, b.y), max(c.y, d.y));
+ float minz = min(min(a.z, b.z), min(c.z, d.z));
+ float maxz = max(max(a.z, b.z), max(c.z, d.z));
+
+
+ if ( amount > 300.0f )
+ {
+ PlayOneShotScriptObject(_SCRSOUND_GLASS_SMASH_1, object->GetPosition());
+
+ GeneratePanesForWindow(0,
+ CVector(minx, miny, minz),
+ CVector(0.0f, 0.0f, maxz-minz),
+ CVector(maxx-minx, maxy-miny, 0.0f),
+ speed, point, 0.1f, !!object->bGlassCracked, explosion);
+ }
+ else
+ {
+ PlayOneShotScriptObject(_SCRSOUND_GLASS_SMASH_2, object->GetPosition());
+
+ GeneratePanesForWindow(1,
+ CVector(minx, miny, minz),
+ CVector(0.0f, 0.0f, maxz-minz),
+ CVector(maxx-minx, maxy-miny, 0.0f),
+ speed, point, 0.1f, !!object->bGlassCracked, explosion);
+ }
+
+ object->bGlassBroken = true;
+ object->GetPosition().z = -100.0f;
+}
+
+void
+CGlass::WindowRespondsToSoftCollision(CEntity *entity, float amount)
+{
+ CObject *object = (CObject *)entity;
+
+ if ( amount > 50.0f && !object->bGlassCracked )
+ {
+ PlayOneShotScriptObject(_SCRSOUND_GLASS_CRACK, object->GetPosition());
+ object->bGlassCracked = true;
+ }
+}
+
+void
+CGlass::WasGlassHitByBullet(CEntity *entity, CVector point)
+{
+ CObject *object = (CObject *)entity;
+
+ if ( IsGlass(object->GetModelIndex()) )
+ {
+ if ( !object->bGlassCracked )
+ {
+ PlayOneShotScriptObject(_SCRSOUND_GLASS_CRACK, object->GetPosition());
+ object->bGlassCracked = true;
+ }
+ else
+ {
+ if ( (CGeneral::GetRandomNumber() & 3) == 2 )
+ WindowRespondsToCollision(object, 0.0f, CVector(0.0f, 0.0f, 0.0f), point, false);
+ }
+ }
+}
+
+void
+CGlass::WindowRespondsToExplosion(CEntity *entity, CVector point)
+{
+ CObject *object = (CObject *)entity;
+
+ CVector distToGlass = object->GetPosition() - point;
+
+ float fDistToGlass = distToGlass.Magnitude();
+
+ if ( fDistToGlass < 10.0f )
+ {
+ distToGlass.Normalise(0.3f);
+ WindowRespondsToCollision(object, 10000.0f, distToGlass, object->GetPosition(), true);
+ }
+ else
+ {
+ if ( fDistToGlass < 30.0f )
+ object->bGlassCracked = true;
+ }
}
-WRAPPER void CGlass::Render(void) { EAXJMP(0x502350); }
-WRAPPER void CGlass::Update(void) { EAXJMP(0x502050); }
-WRAPPER void CGlass::Init(void) { EAXJMP(0x501F20); }
+STARTPATCHES
+ InjectHook(0x501F20, CGlass::Init, PATCH_JUMP);
+ InjectHook(0x502050, CGlass::Update, PATCH_JUMP);
+ InjectHook(0x502080, &CFallingGlassPane::Update, PATCH_JUMP);
+ InjectHook(0x502350, CGlass::Render, PATCH_JUMP);
+ InjectHook(0x502490, CGlass::FindFreePane, PATCH_JUMP);
+ InjectHook(0x5024C0, &CFallingGlassPane::Render, PATCH_JUMP);
+ InjectHook(0x502AC0, CGlass::GeneratePanesForWindow, PATCH_JUMP);
+ InjectHook(0x5033F0, CGlass::AskForObjectToBeRenderedInGlass, PATCH_JUMP);
+ InjectHook(0x503420, CGlass::RenderEntityInGlass, PATCH_JUMP);
+ InjectHook(0x503C90, CGlass::CalcAlphaWithNormal, PATCH_JUMP);
+ InjectHook(0x503D60, CGlass::RenderHiLightPolys, PATCH_JUMP);
+ InjectHook(0x503DE0, CGlass::RenderShatteredPolys, PATCH_JUMP);
+ InjectHook(0x503E70, CGlass::RenderReflectionPolys, PATCH_JUMP);
+ InjectHook(0x503F10, CGlass::WindowRespondsToCollision, PATCH_JUMP);
+ InjectHook(0x504630, CGlass::WindowRespondsToSoftCollision, PATCH_JUMP);
+ InjectHook(0x504670, CGlass::WasGlassHitByBullet, PATCH_JUMP);
+ InjectHook(0x504790, CGlass::WindowRespondsToExplosion, PATCH_JUMP);
+ //InjectHook(0x504880, `global constructor keyed to'glass.cpp, PATCH_JUMP);
+ //InjectHook(0x5048D0, CFallingGlassPane::~CFallingGlassPane, PATCH_JUMP);
+ //InjectHook(0x5048E0, CFallingGlassPane::CFallingGlassPane, PATCH_JUMP);
+ENDPATCHES
diff --git a/src/render/Glass.h b/src/render/Glass.h
index ad4d50f2..dccd9d3d 100644
--- a/src/render/Glass.h
+++ b/src/render/Glass.h
@@ -2,13 +2,52 @@
class CEntity;
+class CFallingGlassPane : public CMatrix
+{
+public:
+ CVector m_vecMoveSpeed;
+ CVector m_vecTurn;
+ uint32 m_nTimer;
+ float m_fGroundZ;
+ float m_fStep;
+ uint8 m_nTriIndex;
+ bool m_bActive;
+ bool m_bShattered;
+ char _pad0[1];
+
+ CFallingGlassPane() { }
+ ~CFallingGlassPane() { }
+
+ void Update(void);
+ void Render(void);
+};
+
+VALIDATE_SIZE(CFallingGlassPane, 0x70);
+
+enum
+{
+ NUM_GLASSTRIANGLES = 5,
+};
+
class CGlass
{
+ static uint32 NumGlassEntities;
+ static CEntity *apEntitiesToBeRendered[NUM_GLASSENTITIES];
+ static CFallingGlassPane aGlassPanes[NUM_GLASSPANES];
public:
- static void AskForObjectToBeRenderedInGlass(CEntity *ent);
- static void WindowRespondsToCollision(CEntity *ent, float amount, CVector speed, CVector point, bool foo);
- static void WindowRespondsToSoftCollision(CEntity *ent, float amount);
- static void Render(void);
- static void Update(void);
static void Init(void);
-};
+ static void Update(void);
+ static void Render(void);
+ static CFallingGlassPane *FindFreePane(void);
+ static void GeneratePanesForWindow(uint32 type, CVector pos, CVector up, CVector right, CVector speed, CVector point, float moveSpeed, bool cracked, bool explosion);
+ static void AskForObjectToBeRenderedInGlass(CEntity *entity);
+ static void RenderEntityInGlass(CEntity *entity);
+ static int32 CalcAlphaWithNormal(CVector *normal);
+ static void RenderHiLightPolys(void);
+ static void RenderShatteredPolys(void);
+ static void RenderReflectionPolys(void);
+ static void WindowRespondsToCollision(CEntity *entity, float amount, CVector speed, CVector point, bool explosion);
+ static void WindowRespondsToSoftCollision(CEntity *entity, float amount);
+ static void WasGlassHitByBullet(CEntity *entity, CVector point);
+ static void WindowRespondsToExplosion(CEntity *entity, CVector point);
+}; \ No newline at end of file
diff --git a/src/render/Hud.cpp b/src/render/Hud.cpp
index f0134062..c4aca8e4 100644
--- a/src/render/Hud.cpp
+++ b/src/render/Hud.cpp
@@ -11,6 +11,7 @@
#include "Pad.h"
#include "Radar.h"
#include "Replay.h"
+#include "Wanted.h"
#include "Sprite.h"
#include "Sprite2d.h"
#include "Text.h"
@@ -102,9 +103,6 @@ struct
RwTexture *&gpSniperSightTex = *(RwTexture**)0x8F5834;
RwTexture *&gpRocketSightTex = *(RwTexture**)0x8E2C20;
-#if 0
-WRAPPER void CHud::Draw(void) { EAXJMP(0x5052A0); }
-#else
void CHud::Draw()
{
// disable hud via second controller
@@ -115,47 +113,43 @@ void CHud::Draw()
return;
if (m_Wants_To_Draw_Hud && !TheCamera.m_WideScreenOn) {
- bool Mode_RunAround = 0;
- bool Mode_FirstPerson = 0;
+ bool DrawCrossHair = 0;
+ bool DrawCrossHairPC = 0;
int32 WeaponType = FindPlayerPed()->m_weapons[FindPlayerPed()->m_currentWeapon].m_eWeaponType;
int32 Mode = TheCamera.Cams[TheCamera.ActiveCam].Mode;
- if (Mode == CCam::MODE_SNIPER || Mode == CCam::MODE_ROCKETLAUNCHER || Mode == CCam::MODE_M16_1STPERSON || Mode == CCam::MODE_EDITOR)
- Mode_FirstPerson = 1;
- if (Mode == CCam::MODE_M16_1STPERSON_RUNABOUT || Mode == CCam::MODE_SNIPER_RUNABOUT)
- Mode_RunAround = 1;
+ if (Mode == CCam::MODE_SNIPER || Mode == CCam::MODE_ROCKETLAUNCHER || Mode == CCam::MODE_M16_1STPERSON || Mode == CCam::MODE_HELICANNON_1STPERSON)
+ DrawCrossHair = 1;
+ if (Mode == CCam::MODE_M16_1STPERSON_RUNABOUT || Mode == CCam::MODE_ROCKETLAUNCHER_RUNABOUT || Mode == CCam::MODE_SNIPER_RUNABOUT)
+ DrawCrossHairPC = 1;
/*
Draw Crosshairs
*/
- if (TheCamera.Cams->Using3rdPersonMouseCam() && (!CPad::GetPad(0)->GetLookBehindForPed() || TheCamera.m_bPlayerIsInGarage) || Mode == CCam::MODE_1STPERSON_RUNABOUT) {
+ if (TheCamera.Cams[TheCamera.ActiveCam].Using3rdPersonMouseCam() &&
+ (!CPad::GetPad(0)->GetLookBehindForPed() || TheCamera.m_bPlayerIsInGarage) || Mode == CCam::MODE_1STPERSON_RUNABOUT) {
if (FindPlayerPed() && !FindPlayerPed()->EnteringCar()) {
if ((WeaponType >= WEAPONTYPE_COLT45 && WeaponType <= WEAPONTYPE_M16) || WeaponType == WEAPONTYPE_FLAMETHROWER)
- Mode_RunAround = 1;
+ DrawCrossHairPC = 1;
}
}
- if (Mode_FirstPerson || Mode_RunAround) {
+ if (DrawCrossHair || DrawCrossHairPC) {
RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void *)rwFILTERLINEAR);
- int32 SpriteBrightLikeADiamond = SpriteBrightness + 1;
- if (SpriteBrightLikeADiamond > 30)
- SpriteBrightLikeADiamond = 30;
-
- SpriteBrightness = SpriteBrightLikeADiamond;
+ SpriteBrightness = min(SpriteBrightness+1, 30);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE);
- float fStep = Sin((CTimer::GetTimeInMilliseconds() & 1023) * 0.0061328127);
+ float fStep = Sin((CTimer::GetTimeInMilliseconds() & 1023)/1024.0f * 6.28f);
float fMultBright = SpriteBrightness * 0.03f * (0.25f * fStep + 0.75f);
CRect rect;
+ if (DrawCrossHairPC && TheCamera.Cams[TheCamera.ActiveCam].Using3rdPersonMouseCam()) {
#ifndef ASPECT_RATIO_SCALE
- if (Mode_RunAround && TheCamera.Cams->Using3rdPersonMouseCam()) {
float f3rdX = SCREEN_WIDTH * TheCamera.m_f3rdPersonCHairMultX;
float f3rdY = SCREEN_HEIGHT * TheCamera.m_f3rdPersonCHairMultY;
#else
- if (Mode_RunAround && TheCamera.Cams->Using3rdPersonMouseCam()) {
float f3rdX = (((TheCamera.m_f3rdPersonCHairMultX - 0.5f) / ((CDraw::GetAspectRatio()) / (DEFAULT_ASPECT_RATIO))) + 0.5f) * SCREEN_WIDTH;
float f3rdY = SCREEN_HEIGHT * TheCamera.m_f3rdPersonCHairMultY + SCREEN_SCALE_Y(-2.0f);
#endif
@@ -179,14 +173,14 @@ void CHud::Draw()
else {
if (Mode == CCam::MODE_M16_1STPERSON ||
Mode == CCam::MODE_M16_1STPERSON_RUNABOUT ||
- Mode == CCam::MODE_EDITOR) {
+ Mode == CCam::MODE_HELICANNON_1STPERSON) {
rect.left = (SCREEN_WIDTH / 2) - SCREEN_SCALE_X(32.0f);
rect.top = (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(32.0f);
rect.right = (SCREEN_WIDTH / 2) + SCREEN_SCALE_X(32.0f);
rect.bottom = (SCREEN_HEIGHT / 2) + SCREEN_SCALE_Y(32.0f);
Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255));
}
- else if (Mode == CCam::MODE_ROCKETLAUNCHER_RUNABOUT) {
+ else if (Mode == CCam::MODE_1STPERSON_RUNABOUT) {
rect.left = (SCREEN_WIDTH / 2) - SCREEN_SCALE_X(32.0f * 0.7f);
rect.top = (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(32.0f * 0.7f);
rect.right = (SCREEN_WIDTH / 2) + SCREEN_SCALE_X(32.0f * 0.7f);
@@ -194,17 +188,18 @@ void CHud::Draw()
Sprites[HUD_SITEM16].Draw(CRect(rect), CRGBA(255, 255, 255, 255));
}
- else if (Mode == CCam::MODE_ROCKETLAUNCHER || Mode == CCam::MODE_SNIPER_RUNABOUT) {
+ else if (Mode == CCam::MODE_ROCKETLAUNCHER || Mode == CCam::MODE_ROCKETLAUNCHER_RUNABOUT) {
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE);
RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE);
RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE);
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)FALSE);
RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE);
- RwRenderStateSet(rwRENDERSTATETEXTURERASTER, gpRocketSightTex->raster);
+ RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(gpRocketSightTex));
CSprite::RenderOneXLUSprite(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 1.0f, SCREEN_SCALE_X(40.0f), SCREEN_SCALE_Y(40.0f), (100.0f * fMultBright), (200.0f * fMultBright), (100.0f * fMultBright), 255, 1.0f, 255);
}
else {
+ // Sniper
rect.left = (SCREEN_WIDTH / 2) - SCREEN_SCALE_X(210.0f);
rect.top = (SCREEN_HEIGHT / 2) - SCREEN_SCALE_Y(210.0f);
rect.right = SCREEN_WIDTH / 2;
@@ -798,8 +793,11 @@ void CHud::Draw()
if (m_ItemToFlash == ITEM_RADAR && CTimer::GetFrameCounter() & 8 || m_ItemToFlash != ITEM_RADAR) {
CRadar::DrawMap();
CRect rect(0.0f, 0.0f, SCREEN_SCALE_X(RADAR_WIDTH), SCREEN_SCALE_Y(RADAR_HEIGHT));
- // FIX? scale RADAR_LEFT here somehow
+#ifdef FIX_BUGS
+ rect.Translate(SCREEN_SCALE_X(RADAR_LEFT), SCREEN_SCALE_FROM_BOTTOM(RADAR_BOTTOM + RADAR_HEIGHT));
+#else
rect.Translate(RADAR_LEFT, SCREEN_SCALE_FROM_BOTTOM(RADAR_BOTTOM + RADAR_HEIGHT));
+#endif
rect.Grow(4.0f);
Sprites[HUD_RADARDISC].Draw(rect, CRGBA(0, 0, 0, 255));
CRadar::DrawBlips();
@@ -1006,12 +1004,7 @@ void CHud::Draw()
}
}
}
-#endif
-
-#if 0
-WRAPPER void CHud::DrawAfterFade(void) { EAXJMP(0x509030); }
-#else
void CHud::DrawAfterFade()
{
if (CTimer::GetIsUserPaused() || CReplay::IsPlayingBack())
@@ -1104,7 +1097,6 @@ void CHud::DrawAfterFade()
CFont::SetColor(CRGBA(175, 175, 175, 255));
CFont::PrintString(SCREEN_SCALE_X(26.0f), SCREEN_SCALE_Y(28.0f + (150.0f - PagerXOffset) * 0.6f), CHud::m_HelpMessageToPrint);
CFont::SetAlphaFade(255.0f);
- CFont::DrawFonts();
}
}
else
@@ -1263,11 +1255,7 @@ void CHud::DrawAfterFade()
BigMessageInUse[1] = 0.0f;
}
}
-#endif
-#if 0
-WRAPPER void CHud::GetRidOfAllHudMessages(void) { EAXJMP(0x504F90); }
-#else
void CHud::GetRidOfAllHudMessages()
{
m_ZoneState = 0;
@@ -1303,7 +1291,6 @@ void CHud::GetRidOfAllHudMessages()
m_BigMessage[i][j] = 0;
}
}
-#endif
void CHud::Initialise()
{
@@ -1345,9 +1332,6 @@ void CHud::Initialise()
CTxdStore::PopCurrentTxd();
}
-#if 0
-WRAPPER void CHud::ReInitialise(void) { EAXJMP(0x504CC0); }
-#else
void CHud::ReInitialise() {
m_Wants_To_Draw_Hud = true;
m_Wants_To_Draw_3dMarkers = true;
@@ -1369,12 +1353,9 @@ void CHud::ReInitialise() {
PagerSoundPlayed = 0;
PagerXOffset = 150.0f;
}
-#endif
wchar LastBigMessage[6][128];
-#if 0
-WRAPPER void CHud::SetBigMessage(wchar *message, int16 style) { EAXJMP(0x50A250); }
-#else
+
void CHud::SetBigMessage(wchar *message, int16 style)
{
int i = 0;
@@ -1402,11 +1383,7 @@ void CHud::SetBigMessage(wchar *message, int16 style)
LastBigMessage[style][i] = 0;
m_BigMessage[style][i] = 0;
}
-#endif
-#if 0
-WRAPPER void CHud::SetHelpMessage(wchar *message, bool quick) { EAXJMP(0x5051E0); }
-#else
void CHud::SetHelpMessage(wchar *message, bool quick)
{
if (!CReplay::IsPlayingBack()) {
@@ -1421,11 +1398,7 @@ void CHud::SetHelpMessage(wchar *message, bool quick)
m_HelpMessageQuick = quick;
}
}
-#endif
-#if 0
-WRAPPER void CHud::SetMessage(wchar *message) { EAXJMP(0x50A210); }
-#else
void CHud::SetMessage(wchar *message)
{
int i = 0;
@@ -1437,11 +1410,7 @@ void CHud::SetMessage(wchar *message)
}
m_Message[i] = 0;
}
-#endif
-#if 0
-WRAPPER void CHud::SetPagerMessage(wchar *message) { EAXJMP(0x50A320); }
-#else
void CHud::SetPagerMessage(wchar *message)
{
int i = 0;
@@ -1453,25 +1422,16 @@ void CHud::SetPagerMessage(wchar *message)
}
m_PagerMessage[i] = 0;
}
-#endif
-#if 0
-WRAPPER void CHud::SetVehicleName(wchar *name) { EAXJMP(0x505290); }
-#else
void CHud::SetVehicleName(wchar *name)
{
m_VehicleName = name;
}
-#endif
-#if 0
-WRAPPER void CHud::SetZoneName(wchar *name) { EAXJMP(0x5051D0); }
-#else
void CHud::SetZoneName(wchar *name)
{
m_pZoneName = name;
}
-#endif
void CHud::Shutdown()
{
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index ff9f5755..d7834065 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -645,6 +645,9 @@ CRenderer::ScanWorld(void)
m_loadingPriority = false;
if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN ||
+#ifdef FIX_BUGS
+ TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_GTACLASSIC ||
+#endif
TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){
CRect rect;
int x1, x2, y1, y2;
@@ -756,6 +759,9 @@ CRenderer::RequestObjectsInFrustum(void)
RwV3dTransformPoints((RwV3d*)vectors, (RwV3d*)vectors, 9, cammatrix);
if(TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOPDOWN ||
+#ifdef FIX_BUGS
+ TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_GTACLASSIC ||
+#endif
TheCamera.Cams[TheCamera.ActiveCam].Mode == CCam::MODE_TOP_DOWN_PED){
CRect rect;
int x1, x2, y1, y2;
diff --git a/src/render/Rubbish.cpp b/src/render/Rubbish.cpp
index c336eb47..a52e59a0 100644
--- a/src/render/Rubbish.cpp
+++ b/src/render/Rubbish.cpp
@@ -7,3 +7,4 @@ WRAPPER void CRubbish::StirUp(CVehicle *veh) { EAXJMP(0x512690); }
WRAPPER void CRubbish::Update(void) { EAXJMP(0x511B90); }
WRAPPER void CRubbish::SetVisibility(bool) { EAXJMP(0x512AA0); }
WRAPPER void CRubbish::Init(void) { EAXJMP(0x511940); }
+WRAPPER void CRubbish::Shutdown(void) { EAXJMP(0x511B50); }
diff --git a/src/render/Rubbish.h b/src/render/Rubbish.h
index c94ff303..17323694 100644
--- a/src/render/Rubbish.h
+++ b/src/render/Rubbish.h
@@ -10,4 +10,5 @@ public:
static void Update(void);
static void SetVisibility(bool);
static void Init(void);
+ static void Shutdown(void);
};
diff --git a/src/render/Shadows.h b/src/render/Shadows.h
index 66df0273..982cc463 100644
--- a/src/render/Shadows.h
+++ b/src/render/Shadows.h
@@ -182,3 +182,4 @@ extern RwTexture *&gpGoalTex;
extern RwTexture *&gpOutline1Tex;
extern RwTexture *&gpOutline2Tex;
extern RwTexture *&gpOutline3Tex;
+extern RwTexture *&gpCrackedGlassTex;
diff --git a/src/render/Skidmarks.cpp b/src/render/Skidmarks.cpp
index deb5a648..c2725ed6 100644
--- a/src/render/Skidmarks.cpp
+++ b/src/render/Skidmarks.cpp
@@ -9,3 +9,4 @@ WRAPPER void CSkidmarks::Render(void) { EAXJMP(0x5182E0); }
WRAPPER void CSkidmarks::RegisterOne(uint32 id, CVector pos, float fwdx, float fwdY, bool *isMuddy, bool *isBloddy) { EAXJMP(0x5185C0); }
WRAPPER void CSkidmarks::Init(void) { EAXJMP(0x517D70); }
+WRAPPER void CSkidmarks::Shutdown(void) { EAXJMP(0x518100); }
diff --git a/src/render/Skidmarks.h b/src/render/Skidmarks.h
index 2f669575..bf2da7e4 100644
--- a/src/render/Skidmarks.h
+++ b/src/render/Skidmarks.h
@@ -8,4 +8,5 @@ public:
static void Render(void);
static void RegisterOne(uint32 id, CVector pos, float fwdx, float fwdY, bool *isMuddy, bool *isBloddy);
static void Init(void);
+ static void Shutdown(void);
};
diff --git a/src/render/SpecialFX.cpp b/src/render/SpecialFX.cpp
index 8ec2d9a1..301ae265 100644
--- a/src/render/SpecialFX.cpp
+++ b/src/render/SpecialFX.cpp
@@ -20,6 +20,7 @@
WRAPPER void CSpecialFX::Render(void) { EAXJMP(0x518DC0); }
WRAPPER void CSpecialFX::Update(void) { EAXJMP(0x518D40); }
WRAPPER void CSpecialFX::Init(void) { EAXJMP(0x5189E0); }
+WRAPPER void CSpecialFX::Shutdown(void) { EAXJMP(0x518BE0); }
WRAPPER void CMotionBlurStreaks::RegisterStreak(int32 id, uint8 r, uint8 g, uint8 b, CVector p1, CVector p2) { EAXJMP(0x519460); }
diff --git a/src/render/SpecialFX.h b/src/render/SpecialFX.h
index 701b89a0..fc155a53 100644
--- a/src/render/SpecialFX.h
+++ b/src/render/SpecialFX.h
@@ -6,6 +6,7 @@ public:
static void Render(void);
static void Update(void);
static void Init(void);
+ static void Shutdown(void);
};
class CMotionBlurStreaks
diff --git a/src/render/WaterCannon.cpp b/src/render/WaterCannon.cpp
index 7a9aa4d9..e848fb43 100644
--- a/src/render/WaterCannon.cpp
+++ b/src/render/WaterCannon.cpp
@@ -1,10 +1,320 @@
#include "common.h"
#include "patcher.h"
#include "WaterCannon.h"
+#include "Vector.h"
+#include "General.h"
+#include "main.h"
+#include "Timer.h"
+#include "Pools.h"
+#include "Ped.h"
+#include "AnimManager.h"
+#include "Fire.h"
+#include "WaterLevel.h"
+#include "Camera.h"
-CWaterCannon (&aCannons)[NUM_WATERCANNONS] = *(CWaterCannon(*)[NUM_WATERCANNONS])*(uintptr*)0x8F2CA8;
+#define WATERCANNONVERTS 4
+#define WATERCANNONINDEXES 12
-WRAPPER void CWaterCannons::Update(void) { EAXJMP(0x522510); }
-WRAPPER void CWaterCannons::UpdateOne(uint32 id, CVector *pos, CVector *dir) { EAXJMP(0x522470); }
-WRAPPER void CWaterCannons::Render(void) { EAXJMP(0x522550); }
-WRAPPER void CWaterCannons::Init(void) { EAXJMP(0x522440); }
+RwIm3DVertex WaterCannonVertices[WATERCANNONVERTS];
+RwImVertexIndex WaterCannonIndexList[WATERCANNONINDEXES];
+
+CWaterCannon CWaterCannons::aCannons[NUM_WATERCANNONS];
+
+void CWaterCannon::Init(void)
+{
+ m_nId = 0;
+ m_nCur = 0;
+ m_nTimeCreated = CTimer::GetTimeInMilliseconds();
+
+ for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ )
+ m_abUsed[i] = false;
+
+ RwIm3DVertexSetU(&WaterCannonVertices[0], 0.0f);
+ RwIm3DVertexSetV(&WaterCannonVertices[0], 0.0f);
+
+ RwIm3DVertexSetU(&WaterCannonVertices[1], 1.0f);
+ RwIm3DVertexSetV(&WaterCannonVertices[1], 0.0f);
+
+ RwIm3DVertexSetU(&WaterCannonVertices[2], 0.0f);
+ RwIm3DVertexSetV(&WaterCannonVertices[2], 0.0f);
+
+ RwIm3DVertexSetU(&WaterCannonVertices[3], 1.0f);
+ RwIm3DVertexSetV(&WaterCannonVertices[3], 0.0f);
+
+ WaterCannonIndexList[0] = 0;
+ WaterCannonIndexList[1] = 1;
+ WaterCannonIndexList[2] = 2;
+
+ WaterCannonIndexList[3] = 1;
+ WaterCannonIndexList[4] = 3;
+ WaterCannonIndexList[5] = 2;
+
+ WaterCannonIndexList[6] = 0;
+ WaterCannonIndexList[7] = 2;
+ WaterCannonIndexList[8] = 1;
+
+ WaterCannonIndexList[9] = 1;
+ WaterCannonIndexList[10] = 2;
+ WaterCannonIndexList[11] = 3;
+}
+
+void CWaterCannon::Update_OncePerFrame(int16 index)
+{
+ ASSERT(index < NUM_WATERCANNONS);
+
+ if (CTimer::GetTimeInMilliseconds() > m_nTimeCreated + WATERCANNON_LIFETIME )
+ {
+ m_nCur = (m_nCur + 1) % -NUM_SEGMENTPOINTS;
+ m_abUsed[m_nCur] = false;
+ }
+
+ for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ )
+ {
+ if ( m_abUsed[i] )
+ {
+ m_avecVelocity[i].z += -WATERCANNON_GRAVITY * CTimer::GetTimeStep();
+ m_avecPos[i] += m_avecVelocity[i] * CTimer::GetTimeStep();
+ }
+ }
+
+ int32 extinguishingPoint = CGeneral::GetRandomNumber() & (NUM_SEGMENTPOINTS - 1);
+ if ( m_abUsed[extinguishingPoint] )
+ gFireManager.ExtinguishPoint(m_avecPos[extinguishingPoint], 3.0f);
+
+ if ( ((index + CTimer::GetFrameCounter()) & 3) == 0 )
+ PushPeds();
+
+ // free if unused
+
+ int32 i = 0;
+ while ( 1 )
+ {
+ if ( m_abUsed[i] )
+ break;
+
+ if ( ++i >= NUM_SEGMENTPOINTS )
+ {
+ m_nId = 0;
+ return;
+ }
+ }
+}
+
+void CWaterCannon::Update_NewInput(CVector *pos, CVector *dir)
+{
+ ASSERT(pos != NULL);
+ ASSERT(dir != NULL);
+
+ m_avecPos[m_nCur] = *pos;
+ m_avecVelocity[m_nCur] = *dir;
+ m_abUsed[m_nCur] = true;
+}
+
+void CWaterCannon::Render(void)
+{
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE);
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE);
+ RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)TRUE);
+ RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpWaterRaster);
+
+ float v = float(CGeneral::GetRandomNumber() & 255) / 256;
+
+ RwIm3DVertexSetV(&WaterCannonVertices[0], v);
+ RwIm3DVertexSetV(&WaterCannonVertices[1], v);
+ RwIm3DVertexSetV(&WaterCannonVertices[2], v);
+ RwIm3DVertexSetV(&WaterCannonVertices[3], v);
+
+ int16 pointA = m_nCur % -NUM_SEGMENTPOINTS;
+
+ int16 pointB = pointA - 1;
+ if ( (pointA - 1) < 0 )
+ pointB += NUM_SEGMENTPOINTS;
+
+ bool bInit = false;
+ CVector norm;
+
+ for ( int32 i = 0; i < NUM_SEGMENTPOINTS - 1; i++ )
+ {
+ if ( m_abUsed[pointA] && m_abUsed[pointB] )
+ {
+ if ( !bInit )
+ {
+ CVector cp = CrossProduct(m_avecPos[pointB] - m_avecPos[pointA], TheCamera.GetForward());
+ cp.Normalise(0.05f);
+ norm = cp;
+ bInit = true;
+ }
+
+ float dist = float(i*i*i) / 300.0f + 1.0f;
+ float brightness = float(i) / NUM_SEGMENTPOINTS;
+
+ int32 color = (int32)((1.0f - brightness*brightness) * 255.0f);
+ CVector offset = dist * norm;
+
+ RwIm3DVertexSetRGBA(&WaterCannonVertices[0], color, color, color, color);
+ RwIm3DVertexSetPos (&WaterCannonVertices[0], m_avecPos[pointA].x - offset.x, m_avecPos[pointA].y - offset.y, m_avecPos[pointA].z - offset.z);
+
+ RwIm3DVertexSetRGBA(&WaterCannonVertices[1], color, color, color, color);
+ RwIm3DVertexSetPos (&WaterCannonVertices[1], m_avecPos[pointA].x + offset.x, m_avecPos[pointA].y + offset.y, m_avecPos[pointA].z + offset.z);
+
+ RwIm3DVertexSetRGBA(&WaterCannonVertices[2], color, color, color, color);
+ RwIm3DVertexSetPos (&WaterCannonVertices[2], m_avecPos[pointB].x - offset.x, m_avecPos[pointB].y - offset.y, m_avecPos[pointB].z - offset.z);
+
+ RwIm3DVertexSetRGBA(&WaterCannonVertices[3], color, color, color, color);
+ RwIm3DVertexSetPos (&WaterCannonVertices[3], m_avecPos[pointB].x + offset.x, m_avecPos[pointB].y + offset.y, m_avecPos[pointB].z + offset.z);
+
+ LittleTest();
+
+ if ( RwIm3DTransform(WaterCannonVertices, WATERCANNONVERTS, NULL, rwIM3D_VERTEXUV) )
+ {
+ RwIm3DRenderIndexedPrimitive(rwPRIMTYPETRILIST, WaterCannonIndexList, WATERCANNONINDEXES);
+ RwIm3DEnd();
+ }
+ }
+
+ pointA = pointB--;
+ if ( pointB < 0 )
+ pointB += NUM_SEGMENTPOINTS;
+ }
+
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)TRUE);
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE);
+ RwRenderStateSet(rwRENDERSTATEFOGENABLE, (void *)FALSE);
+}
+
+void CWaterCannon::PushPeds(void)
+{
+ float minx = 10000.0f;
+ float maxx = -10000.0f;
+ float miny = 10000.0f;
+ float maxy = -10000.0f;
+ float minz = 10000.0f;
+ float maxz = -10000.0f;
+
+ for ( int32 i = 0; i < NUM_SEGMENTPOINTS; i++ )
+ {
+ if ( m_abUsed[i] )
+ {
+ minx = min(minx, m_avecPos[i].x);
+ maxx = max(maxx, m_avecPos[i].x);
+
+ miny = min(miny, m_avecPos[i].y);
+ maxy = max(maxy, m_avecPos[i].y);
+
+ minz = min(minz, m_avecPos[i].z);
+ maxz = max(maxz, m_avecPos[i].z);
+ }
+ }
+
+ for ( int32 i = CPools::GetPedPool()->GetSize() - 1; i >= 0; i--)
+ {
+ CPed *ped = CPools::GetPedPool()->GetSlot(i);
+ if ( ped )
+ {
+ if ( ped->GetPosition().x > minx && ped->GetPosition().x < maxx
+ && ped->GetPosition().y > miny && ped->GetPosition().y < maxy
+ && ped->GetPosition().z > minz && ped->GetPosition().z < maxz )
+ {
+ for ( int32 j = 0; j < NUM_SEGMENTPOINTS; j++ )
+ {
+ if ( m_abUsed[j] )
+ {
+ CVector dist = m_avecPos[j] - ped->GetPosition();
+
+ if ( dist.MagnitudeSqr() < 5.0f )
+ {
+ int32 localDir = ped->GetLocalDirection(CVector2D(1.0f, 0.0f));
+
+ ped->bIsStanding = false;
+
+ ped->ApplyMoveForce(0.0f, 0.0f, 2.0f * CTimer::GetTimeStep());
+
+ ped->m_vecMoveSpeed.x = (0.6f * m_avecVelocity[j].x + ped->m_vecMoveSpeed.x) * 0.5f;
+ ped->m_vecMoveSpeed.y = (0.6f * m_avecVelocity[j].y + ped->m_vecMoveSpeed.y) * 0.5f;
+
+ ped->SetFall(2000, AnimationId(ANIM_KO_SKID_FRONT + localDir), 0);
+
+ CFire *fire = ped->m_pFire;
+ if ( fire )
+ fire->Extinguish();
+
+ j = NUM_SEGMENTPOINTS;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+void CWaterCannons::Init(void)
+{
+ for ( int32 i = 0; i < NUM_WATERCANNONS; i++ )
+ aCannons[i].Init();
+}
+
+void CWaterCannons::UpdateOne(uint32 id, CVector *pos, CVector *dir)
+{
+ ASSERT(pos != NULL);
+ ASSERT(dir != NULL);
+
+ // find the one by id
+ {
+ int32 n = 0;
+ while ( n < NUM_WATERCANNONS && id != aCannons[n].m_nId )
+ n++;
+
+ if ( n < NUM_WATERCANNONS )
+ {
+ aCannons[n].Update_NewInput(pos, dir);
+ return;
+ }
+ }
+
+ // if no luck then find a free one
+ {
+ int32 n = 0;
+ while ( n < NUM_WATERCANNONS && 0 != aCannons[n].m_nId )
+ n++;
+
+ if ( n < NUM_WATERCANNONS )
+ {
+ aCannons[n].Init();
+ aCannons[n].m_nId = id;
+ aCannons[n].Update_NewInput(pos, dir);
+ return;
+ }
+ }
+}
+
+void CWaterCannons::Update(void)
+{
+ for ( int32 i = 0; i < NUM_WATERCANNONS; i++ )
+ {
+ if ( aCannons[i].m_nId != 0 )
+ aCannons[i].Update_OncePerFrame(i);
+ }
+}
+
+void CWaterCannons::Render(void)
+{
+ for ( int32 i = 0; i < NUM_WATERCANNONS; i++ )
+ {
+ if ( aCannons[i].m_nId != 0 )
+ aCannons[i].Render();
+ }
+}
+
+STARTPATCHES
+ InjectHook(0x521A30, &CWaterCannon::Init, PATCH_JUMP);
+ InjectHook(0x521B80, &CWaterCannon::Update_OncePerFrame, PATCH_JUMP);
+ InjectHook(0x521CC0, &CWaterCannon::Update_NewInput, PATCH_JUMP);
+ InjectHook(0x521D30, &CWaterCannon::Render, PATCH_JUMP);
+ InjectHook(0x5220B0, &CWaterCannon::PushPeds, PATCH_JUMP);
+ InjectHook(0x522440, CWaterCannons::Init, PATCH_JUMP);
+ InjectHook(0x522470, CWaterCannons::UpdateOne, PATCH_JUMP);
+ InjectHook(0x522510, CWaterCannons::Update, PATCH_JUMP);
+ InjectHook(0x522550, CWaterCannons::Render, PATCH_JUMP);
+ //InjectHook(0x522B40, `global constructor keyed to'watercannon.cpp, PATCH_JUMP);
+ //InjectHook(0x522B60, CWaterCannon::CWaterCannon, PATCH_JUMP);
+ENDPATCHES \ No newline at end of file
diff --git a/src/render/WaterCannon.h b/src/render/WaterCannon.h
index c2b288f2..826dc78e 100644
--- a/src/render/WaterCannon.h
+++ b/src/render/WaterCannon.h
@@ -1,15 +1,29 @@
#pragma once
+#define WATERCANNON_GRAVITY (0.009f)
+#define WATERCANNON_LIFETIME (150)
+
class CWaterCannon
{
public:
+ enum
+ {
+ NUM_SEGMENTPOINTS = 16,
+ };
+
int32 m_nId;
- int16 m_wIndex;
- char gap_6[2];
- int32 m_nTimeCreated;
- CVector m_avecPos[16];
- CVector m_avecVelocity[16];
- char m_abUsed[16];
+ int16 m_nCur;
+ char _pad0[2];
+ uint32 m_nTimeCreated;
+ CVector m_avecPos[NUM_SEGMENTPOINTS];
+ CVector m_avecVelocity[NUM_SEGMENTPOINTS];
+ bool m_abUsed[NUM_SEGMENTPOINTS];
+
+ void Init(void);
+ void Update_OncePerFrame(int16 index);
+ void Update_NewInput(CVector *pos, CVector *dir);
+ void Render(void);
+ void PushPeds(void);
};
static_assert(sizeof(CWaterCannon) == 412, "CWaterCannon: error");
@@ -17,11 +31,10 @@ static_assert(sizeof(CWaterCannon) == 412, "CWaterCannon: error");
class CWaterCannons
{
public:
- static void Update();
+ static CWaterCannon aCannons[NUM_WATERCANNONS];
+
+ static void Init(void);
static void UpdateOne(uint32 id, CVector *pos, CVector *dir);
+ static void Update();
static void Render(void);
- static void Init(void);
-};
-
-extern CWaterCannon (&aCannons)[NUM_WATERCANNONS];
-
+}; \ No newline at end of file
diff --git a/src/render/WeaponEffects.cpp b/src/render/WeaponEffects.cpp
index 932c661e..2ed9e662 100644
--- a/src/render/WeaponEffects.cpp
+++ b/src/render/WeaponEffects.cpp
@@ -1,45 +1,106 @@
#include "common.h"
#include "patcher.h"
#include "WeaponEffects.h"
-
#include "TxdStore.h"
+#include "Sprite.h"
-WRAPPER void CWeaponEffects::Render(void) { EAXJMP(0x564D70); }
+RwTexture *gpCrossHairTex;
+RwRaster *gpCrossHairRaster;
-CWeaponEffects &gCrossHair = *(CWeaponEffects*)0x6503BC;
+CWeaponEffects gCrossHair;
+
+CWeaponEffects::CWeaponEffects()
+{
+
+}
+
+CWeaponEffects::~CWeaponEffects()
+{
+
+}
void
-CWeaponEffects::ClearCrossHair()
+CWeaponEffects::Init(void)
{
- gCrossHair.m_bCrosshair = false;
+ gCrossHair.m_bActive = false;
+ gCrossHair.m_vecPos = CVector(0.0f, 0.0f, 0.0f);
+ gCrossHair.m_nRed = 0;
+ gCrossHair.m_nGreen = 0;
+ gCrossHair.m_nBlue = 0;
+ gCrossHair.m_nAlpha = 255;
+ gCrossHair.m_fSize = 1.0f;
+ gCrossHair.m_fRotation = 0.0f;
+
+
+ CTxdStore::PushCurrentTxd();
+ int32 slot = CTxdStore::FindTxdSlot("particle");
+ CTxdStore::SetCurrentTxd(slot);
+
+ gpCrossHairTex = RwTextureRead("crosshair", nil);
+ gpCrossHairRaster = RwTextureGetRaster(gpCrossHairTex);
+
+ CTxdStore::PopCurrentTxd();
+}
+
+void
+CWeaponEffects::Shutdown(void)
+{
+ RwTextureDestroy(gpCrossHairTex);
}
void
CWeaponEffects::MarkTarget(CVector pos, uint8 red, uint8 green, uint8 blue, uint8 alpha, float size)
{
- gCrossHair.m_bCrosshair = true;
- gCrossHair.m_vecPos = pos;
- gCrossHair.m_red = red;
- gCrossHair.m_green = green;
- gCrossHair.m_blue = blue;
- gCrossHair.m_alpha = alpha;
- gCrossHair.m_size = size;
+ gCrossHair.m_bActive = true;
+ gCrossHair.m_vecPos = pos;
+ gCrossHair.m_nRed = red;
+ gCrossHair.m_nGreen = green;
+ gCrossHair.m_nBlue = blue;
+ gCrossHair.m_nAlpha = alpha;
+ gCrossHair.m_fSize = size;
+}
+
+void
+CWeaponEffects::ClearCrossHair(void)
+{
+ gCrossHair.m_bActive = false;
}
void
-CWeaponEffects::Init()
+CWeaponEffects::Render(void)
{
- gCrossHair.m_bCrosshair = false;
- gCrossHair.m_vecPos = CVector(0.0f, 0.0f, 0.0f);
- gCrossHair.m_red = 0;
- gCrossHair.m_green = 0;
- gCrossHair.m_blue = 0;
- gCrossHair.m_alpha = 255;
- gCrossHair.m_size = 1.0f;
- gCrossHair.field_24 = 0;
- CTxdStore::PushCurrentTxd();
- CTxdStore::SetCurrentTxd(CTxdStore::FindTxdSlot("particle"));
- gCrossHair.m_pTexture = RwTextureRead("crosshair", nil);
- gCrossHair.m_pRaster = gCrossHair.m_pTexture->raster;
- CTxdStore::PopCurrentTxd();
+ if ( gCrossHair.m_bActive )
+ {
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE);
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)TRUE);
+ RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDONE);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDONE);
+ RwRenderStateSet(rwRENDERSTATETEXTURERASTER, (void *)gpCrossHairRaster);
+
+ RwV3d pos;
+ float w, h;
+ if ( CSprite::CalcScreenCoors(gCrossHair.m_vecPos, &pos, &w, &h, true) )
+ {
+ float recipz = 1.0f / pos.z;
+ CSprite::RenderOneXLUSprite(pos.x, pos.y, pos.z,
+ gCrossHair.m_fSize * w, gCrossHair.m_fSize * h,
+ gCrossHair.m_nRed, gCrossHair.m_nGreen, gCrossHair.m_nBlue, 255,
+ recipz, 255);
+ }
+
+ RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void *)FALSE);
+ RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void *)FALSE);
+ RwRenderStateSet(rwRENDERSTATESRCBLEND, (void *)rwBLENDSRCALPHA);
+ RwRenderStateSet(rwRENDERSTATEDESTBLEND, (void *)rwBLENDINVSRCALPHA);
+ }
}
+
+STARTPATCHES
+ //InjectHook(0x564C40, CWeaponEffects::CWeaponEffects, PATCH_JUMP);
+ //InjectHook(0x564C50, CWeaponEffects::~CWeaponEffects, PATCH_JUMP);
+ InjectHook(0x564C60, CWeaponEffects::Init, PATCH_JUMP);
+ InjectHook(0x564CF0, CWeaponEffects::Shutdown, PATCH_JUMP);
+ InjectHook(0x564D00, CWeaponEffects::MarkTarget, PATCH_JUMP);
+ InjectHook(0x564D60, CWeaponEffects::ClearCrossHair, PATCH_JUMP);
+ InjectHook(0x564D70, CWeaponEffects::Render, PATCH_JUMP);
+ENDPATCHES \ No newline at end of file
diff --git a/src/render/WeaponEffects.h b/src/render/WeaponEffects.h
index e4d0461a..31c5a309 100644
--- a/src/render/WeaponEffects.h
+++ b/src/render/WeaponEffects.h
@@ -3,21 +3,25 @@
class CWeaponEffects
{
public:
- bool m_bCrosshair;
- int8 gap_1[3];
+ bool m_bActive;
+ char _pad[3];
CVector m_vecPos;
- uint8 m_red;
- uint8 m_green;
- uint8 m_blue;
- uint8 m_alpha;
- float m_size;
- int32 field_24;
- RwTexture *m_pTexture;
- RwRaster *m_pRaster;
+ uint8 m_nRed;
+ uint8 m_nGreen;
+ uint8 m_nBlue;
+ uint8 m_nAlpha;
+ float m_fSize;
+ float m_fRotation;
public:
- static void Render(void);
- static void ClearCrossHair();
- static void MarkTarget(CVector, uint8, uint8, uint8, uint8, float);
+ CWeaponEffects();
+ ~CWeaponEffects();
+
static void Init(void);
+ static void Shutdown(void);
+ static void MarkTarget(CVector pos, uint8 red, uint8 green, uint8 blue, uint8 alpha, float size);
+ static void ClearCrossHair(void);
+ static void Render(void);
};
+
+VALIDATE_SIZE(CWeaponEffects, 0x1C); \ No newline at end of file